For today we have project which uses Entity Framework 6 Code-First approach (.NET 4.0).
I'm trying to port this project to Entity Framework Core (.NET Core 2.0) and I faced several problems:
- In EF 6 I used configuration with DbConfigurationTypeAttribute which is missing from EF Core:
Code: Select all
[DbConfigurationType(typeof(Devart.Data.SQLite.Entity.SQLiteEntityProviderServicesConfiguration))]
- In EF 6 to read user_version I used the access to ObjectContext which is missing from EF Core:
Code: Select all
var objContext = ((IObjectContextAdapter)MyDbContext).ObjectContext; var user_version = objContext .ExecuteStoreQuery<long>("PRAGMA [main].user_version").FirstOrDefault();
- In EF 6 I programmatically added data provider using SQLiteConnectionInfo.InvariantName which is missing from Devart.Data.SQLite.Entity.EFCore:
Code: Select all
try { var dataTable = (ConfigurationManager.GetSection("system.data") as DataSet).Tables[0]; //DbProviderFactory is already installed - need to delete it before foreach (DataRow row in dataTable.Rows) if (row[2].Equals(SQLiteConnectionInfo.InvariantName)) { row.Delete(); row.AcceptChanges(); break; } //Add Data Provider dataTable.Rows.Add("dotConnect for SQLite", "dotConnect for SQLite", SQLiteConnectionInfo.InvariantName, "Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.SQLite, Culture=neutral, PublicKeyToken=09af7300eec23701"); } catch (Exception ex) { throw new Exception("DataProvider add error", ex); }
- In EF 6 I used SQLiteEntityMigrationSqlGenerator which is missing from Devart.Data.SQLite.Entity.EFCore:
Code: Select all
internal sealed class MyDbContextMigrationConfiguration : DbMigrationsConfiguration<MyDbContext> { public MyDbContextMigrationConfiguration() { AutomaticMigrationsEnabled = true; AutomaticMigrationDataLossAllowed = false; SetSqlGenerator(SQLiteConnectionInfo.InvariantName, new SQLiteEntityMigrationSqlGenerator()); } } ........................................................ //migration settings Database.SetInitializer(new MigrateDatabaseToLatestVersion<MyDbContext, MyContextMigrationConfiguration>());
Thank you in advance.