Asp.Net Identity,Entity Framework 与 Sqlite

1.Asp.Net Identity Core Reference

Microsoft.AspNet.Identity.Core core library contains the main features of Identity.

Microsoft.AspNet.Identity.EntityFramework including the realization of EF part of ASP.NET Identity.

Microsoft.AspNet.Identity.OWIN ASP.NET Identity of support for OWIN.

Installation: Select to verify identity when creating Asp.Net Web installation or use NuGet

By entering the following command to install Package Manger Console Identity:

  • Install-Package Microsoft.AspNet.Identity.EntityFramework

  • Install-Package Microsoft.AspNet.Identity.OWIN

  • Install-Package Microsoft.Owin.Host.SystemWeb

2.Sqlite quote

System.Data.SQLite

System.Data.SQLite.Core

System.Data.SQLite.EF6

System.Data.SQLite.Linq

SQLite.CodeFirst  使EF CodeFirst支持Sqlite

Nuget the mounting

3.WebConfig configuration, installation Nuget when some did not complete the configuration, you need to ensure that the following node contains the following configuration

 

The connection string used EF DbContext

<connectionStrings>

<add name="SQLiteConnection" providerName="System.Data.SQLite.EF6" connectionString="Data Source=|DataDirectory|\Data.db3;Pooling=True;BinaryGuid=False" />

</connectionStrings>

 

EF registered within the relevant provider Sqlite

<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>

 

4.ApplicationDbContext Configuration

 

The main added OnModelCreating:

the override void OnModelCreating protected (DbModelBuilder modelBuilder)
{
// Sqlite CodeFrist If the database does not exist, create
Database.SetInitializer (new SqliteCreateDatabaseIfNotExists <ApplicationDbContext> ( modelBuilder));

// use ApplicationUser Microsoft.AspNet.Identity.EntityFramework.IdentityUser based, IdentityUserRole IdentityUserLogin with no primary key, here designated

//解决“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);
}

The end configuration may be used

 

Guess you like

Origin www.cnblogs.com/zhiguzhidao/p/12304595.html