0
I am in a WPF project using some MVVM practices, I am using Entity Framework database first and the Connection string is already in the app.config, I have already followed all the procedures I have read in several questions but in the view appears this message in Datacontext
Below the connectionstring that is already in the app.config
<add name="TimerEntities" connectionString="metadata=res://*/Timer.csdl|res://*/Timer.ssdl|res://*/Timer.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=C:\Users\Angelica\Documents\DB\Timer.sdf;Max Database Size=4091""
providerName="System.Data.EntityClient" />
The Context of the Database
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class TimerEntities : DbContext
{
public TimerEntities()
: base("name=TimerEntities")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<CAIXA> CAIXAS { get; set; }
public virtual DbSet<CLIENTE> CLIENTES { get; set; }
public virtual DbSet<ORDEM> ORDEM { get; set; }
public virtual DbSet<PACOTE> PACOTES { get; set; }
public virtual DbSet<TEMPO> TEMPOS { get; set; }
}
Procedures I’ve done that haven’t worked:
- Remove "name" from Context;
- Put the Connection string in another file
configand link toapp.config; - Comment on
throw new UnintentionalCodeFirstException();;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<connectionStrings>
<add name="TimerEntities" connectionString="metadata=res://*/Timer.csdl|res://*/Timer.ssdl|res://*/Timer.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=C:\Users\Angelica\Documents\DB\Timer.sdf;Max Database Size=4091""
providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlServerCe.4.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
</configuration>

I need the contents of
App1.configcomplete. Can you please update your question?– Leonel Sanches da Silva
Good morning, the setup inside your app.config file is right ? You came to make a test to check if the connection with the Bank is being made ?
– Diego Farias
Already edited! Thanks for your help!
– Angélica Flausino
Why does the file call
App1.config? You should just call yourselfApp.config. By doing the Build of his project, he goes on to callSeuProjeto.config.– Leonel Sanches da Silva
Good morning Diego, so when I put the Command on a button my design time appears error of You are using code first in a database that was generated in databasefirst, something like that! Then I had to remove the Command from the button! To better explain this program is a time counter for equipment at a mall kiosk! So I just populated some data in the database! But for example in my viewModel I have a property called tbDataAtual that simply returns Datetime.Now and with this error even this is not returning! Thank you.
– Angélica Flausino
It’s because I thought it was some problem with the original project app.config I deleted it and put another one to test! But it didn’t work anyway!
– Angélica Flausino