本文介绍了移动ASP.NET身份店EF SQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认ASP.NET身份的用户数据被存储在一个MDF文件

By default ASP.NET Identity user data is stored in an mdf file.

我希望将数据存储在SQL数据库中,以便我在的web.config改defaultconnection字符串我的EF基于连接:

I want to store the data in a Sql database so that I changed the defaultconnection string in my web.config to my EF based connection:

 <add name="DefaultConnection" connectionString="metadata=res://*/Models.StartifyModel.csdl|res://*/Models.StartifyModel.ssdl|res://*/Models.StartifyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYPC\SQLEXPRESS;initial catalog=mydb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

现在我得到的错误的实体类型ApplicationUser是不是该机型为当前上下文的一部分。只要我想注册一个用户。

Now I am getting the error The entity type ApplicationUser is not part of the model for the current context. as soon as I want to register a user.

我用VS2013的默认​​MVC5项目模板。

I use the default MVC5 project template of VS2013.

推荐答案

请尝试指定格式的连接字符串:

Please try specify the connection string in the format:

<add name="DefaultConnection" connectionString="Data Source=127.0.0.1, 1433;Initial Catalog=YourDB;User Id=XXXX;Password=XXXXX;Asynchronous Processing=True;Encrypt=False;TrustServerCertificate=True;Persist Security Info=True" providerName="System.Data.SqlClient" />

然后确保在型号/ IdentityModels.cs你有

And then make sure in Models/IdentityModels.cs you have

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("DefaultConnection")
        {
        }

这篇关于移动ASP.NET身份店EF SQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 20:15