I am upgrading a .net framework 4.5 project to .net core 2.1, which uses EF6 and has undergone some modifications:
- Changes in the namespace can basically be supplemented by automatic prompts, and there is no need to memorize them.
- The return result of DbQuery<T> is changed to: IQueryable<T>.
- The Include method already supports incoming types, so extensions are no longer required.
- DbContext.Configuration.AutoDetectChangesEnabled property moved to: DbContext.ChangeTracker.AutoDetectChangesEnabled.
- In a custom class that inherits from DbContext, the connection string can be defined using the OnConfiguring override method, such as:
public partial class SenparcEntities: DbContext { /// <summary> /// Connection String /// </summary> internal string ConnectionString { get ; set ; } public DbSet<Account> Accounts { get; set; } public DbSet<SystemConfig> SystemConfigs { get; set; } public SenparcEntities(string connectionString) { ConnectionString = connectionString; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { // Configure the connection string optionsBuilder.UseSqlServer(ConnectionString); base.OnConfiguring(optionsBuilder); } }