标签:guid protect mic cte tin 包括 ram codefirst app
Microsoft.AspNet.Identity.Core 核心库,包含Identity的主要功能。
Microsoft.AspNet.Identity.EntityFramework 主要包括ASP.NET Identity 的EF 部分的实现。
Microsoft.AspNet.Identity.OWIN ASP.NET Identity对OWIN 的支持。
安装方式:创建Asp.Net Web 时选择身份验证或者使用NuGet安装
通过在Package Manger Console输入如下命令来安装Identity:
Install-Package Microsoft.AspNet.Identity.EntityFramework
Install-Package Microsoft.AspNet.Identity.OWIN
Install-Package Microsoft.Owin.Host.SystemWeb
System.Data.SQLite
System.Data.SQLite.Core
System.Data.SQLite.EF6
System.Data.SQLite.Linq
SQLite.CodeFirst 使EF CodeFirst支持Sqlite
Nuget内安装
EF DbContext使用的连接字符串
<connectionStrings>
<add name="SQLiteConnection" providerName="System.Data.SQLite.EF6" connectionString="Data Source=|DataDirectory|\Data.db3;Pooling=True;BinaryGuid=False" />
</connectionStrings>
EF内注册Sqlite相关provider
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<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>
主要添加OnModelCreating:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
//Sqlite CodeFrist如果不存在数据库,则创建
Database.SetInitializer(new SqliteCreateDatabaseIfNotExists<ApplicationDbContext>(modelBuilder));
//使用基于Microsoft.AspNet.Identity.EntityFramework.IdentityUser的ApplicationUser时,IdentityUserRole与IdentityUserLogin没有主键,在此指定
//解决“EntityType ‘IdentityUserLogin‘ has no key defined”及“EntityType ‘IdentityUserRole‘ has no key defined”错误
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.UserId, r.RoleId });
modelBuilder.Entity<IdentityUserLogin>().HasKey(r => r.UserId);
//base.OnModelCreating(modelBuilder);
}
Asp.Net Identity,Entity Framework 与 Sqlite
标签:guid protect mic cte tin 包括 ram codefirst app
原文地址:https://www.cnblogs.com/zhiguzhidao/p/12304595.html