1.参考原文链接:http://msdn.microsoft.com/en-us/data/jj680699#Using
2.sqlite 用Nuget添加System.Data.Sqlite总是错误。配置文件怎么改都报错,于是想到了用代码来配置,现在来记录下。
public class SQLiteConfiguration : DbConfiguration
{
public SQLiteConfiguration()
{
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
Type t = Type.GetType(
"System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6");
FieldInfo fi = t.GetField("Instance", BindingFlags.NonPublic | BindingFlags.Static);
SetProviderServices("System.Data.SQLite", (DbProviderServices)fi.GetValue(null));
}
}
[DbConfigurationType(typeof(SQLiteConfiguration))]
public class AdminContext : DbContext
{
public AdminContext() : base("name=AdminContext") { }
public AdminContext(DbConnection db ) : base(db,false) { }
public DbSet<User> User { set; get; }
}