Witam,
mam problem z utworzeniem i dodaniem wpisu do bazy danych SQLite za pomocą frameworka Entity, pojawia się błąd: "Sequence contains no matching element".
Oto moje klasy modelowe oraz ustawienia połączenia:
public class Operator
{
public Operator() { }
[Key]
public int Id { get; set; }
public string Login { get; set; }
}
public class BaseContext : DbContext
{
public BaseContext() : base("name=MyContext") {
}
public DbSet<Operator> Operators { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Configure default schema
base.OnModelCreating(modelBuilder);
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
static BaseContext()
{
Database.SetInitializer<BaseContext>(new CreateDatabaseIfNotExists<BaseContext>());
}
}
Metoda wywoływana
private void CreateDbEntity()
{
using (var ctx = new BaseContext())
{
Operator user = new Operator() { Login = "aaa" };
ctx.Operators.Add(user); // tutaj występuje błąd: "Sequence contains no matching element"
ctx.SaveChanges();
}
}
Ustawienia w pliku App.config
<connectionStrings>
<add name="MyContext" connectionString="Data Source=D:\Test.sqlite" providerName="System.Data.SQLite.EF6" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v13.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>