I am getting an issue that I have seen posted before but the answers seem only applicable to ASP.NET MVC, whereas I am using WPF (with Entity Framework).
My XAML designer in VS currently looks like this:
This is on a UserControl
where the code is very simple:
<UserControl x:Class="door_system.Views.HomeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:viewModels="clr-namespace:door_system.ViewModels"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<viewModels:HomeViewModel/>
</UserControl.DataContext>
<Grid>
<DataGrid AutoGenerateColumns="False">
<DataGridTextColumn Width="*"/>
<DataGridTextColumn Width="*"/>
<DataGridTextColumn Width="*"/>
</DataGrid>
</Grid>
</UserControl>
So my project setup looks like so:
There is only one app.config
file that definitely contains the connection string:
<connectionStrings>
<add name="MicrotrakContext" connectionString="metadata=res://*/Models.MicrotrakModel.csdl|res://*/Models.MicrotrakModel.ssdl|res://*/Models.MicrotrakModel.msl;provider=System.Data.SqlClient;provider connection string="data source=*******;initial catalog=MicrotrakEvolution;user id=******;password=********;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
When I build the project there are no errors. When I run the project it performs without error too. Is this a bug I have discovered?
Aside from name changes I have two other projects that are setup in almost exactly the same way, both build and run without issue.
The Task calling the Context in HomeViewModel
:
private Task LoadTransactionsTask()
{
return Task.Run(() =>
{
using (var context = new MicrotrakContext())
{
AllTransactions = new ObservableCollection<Transaction>(
(from record in context.Transactions
select record)
.Where(x => x.CreationTime >= DateTime.Today)
.ToList());
}
});
}