1、
namespace Snapsia.Web.Models { using System; using System.Data.Entity; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; [DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))] public partial class SnapsiaContext : DbContext { public SnapsiaContext() : base("name=SnapsiaContext") { } public virtual DbSet<InfluencersUser> InfluencersUser { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { } } }
2、表“TableDetails”中列“IsPrimaryKey”的值为 DBNull
解决办法:
set global optimizer_switch='derived_merge=OFF';
http://stackoverflow.com/questions/33575109/mysql-entity-the-value-for-column-isprimarykey-in-table-tabledetails-is
http://bugs.mysql.com/bug.php?id=79163
https://dev.mysql.com/doc/refman/5.7/en/switchable-optimizations.html
3、
[Table("TB_USER", Schema = "USER_SNAPSIA")]//dbo架构在oracle数据库为用户名 public partial class TB_USER { [Key] [StringLength(50)] public string ID { get; set; } [StringLength(50)] public string USERNAME { get; set; } [StringLength(50)] public string PWD { get; set; } }
public partial class OrclContext : DbContext { public OrclContext() : base("name=OrclContext") { } public virtual DbSet<TB_USER> TB_USER { get; set; } public virtual DbSet<TB_SYYS> TB_SYYS { get; set; } public virtual DbSet<TB_CCT> TB_CCT { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.HasDefaultSchema("USER_SNAPSIA"); //dbo架构在oracle数据库为用户名 modelBuilder.Entity<TB_USER>() .Property(e => e.ID) .IsUnicode(false); } }
4、VS2015 update3 +MySQL5.7+EntityFramework Code First
从数据库生成Code First 代码,选择连接后点击下一步,界面闪退,无法生成的解决办法。
需要安装最新版的两个组件:
mysql-connector-net-6.9.9
mysql-for-visualstudio-1.2.6
5、使用同一个上下文对象:
public static SnapsiaContext GetCurrentDbSession() { SnaContext context = CallContext.GetData(typeof(DbSessionContextFactory).FullName) as SnaContext; if (context == null) { context = new SnaContext(); CallContext.SetData(typeof(DbSessionContextFactory).FullName, context); } return context; }
6、EntityFramework Code First 优化
6.1、推荐使用IIS8.
6.2、参考文章:亲授MVC5中EF6 Code First启动慢及间隙变慢优化的实践经验
https://weblog.west-wind.com/posts/2013/Oct/02/Use-IIS-Application-Initialization-for-keeping-ASPNET-Apps-alive?utm_source=tuicool#GettingstartedwithApplicationInitialization
http://www.cnblogs.com/hantianwei/archive/2013/04/26/3044157.html