Owin OAuth provider “The entity type IdentityUser is not part of the model for the current context”

心已入冬 提交于 2019-12-22 00:15:35

问题


UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>());
OAuthOptions = new OAuthAuthorizationServerOptions
{
    TokenEndpointPath = new PathString("/Token"),
    Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
    AuthorizeEndpointPath = new PathString("/api/AccountOwin/ExternalLogin"),
    AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
    AllowInsecureHttp = true
};

From which IdentityUser,UserStore comesform entity framework.

I want to use my database instead of local db, I generated the "generate" script from the local db tables and I created them in my custom database but when I chanhe the db context in the below row:

UserManagerFactory = () => new UserManager<IdentityUser>(new UserStore<IdentityUser>(new MyCustomDBEntities()));

Where MyCustomDBEntities is my custom database in entity framework (edmx) I'm getting the following error: "The entity type IdentityUser is not part of the model for the current context"

What I am doing wrong? Should I create my own Usermanager?

public class MyCustomDBEntities : IdentityDbContext<IdentityUser>
    {
        public MyCustomDBEntities()
            : base("name=ConnectionStringName")
        {
        }
    }

回答1:


I suspect the problem is with your connection string. First of all, the constructor of your context only needs to have the name of the connection string, so you can change it to this:

public MyCustomDBEntities() : base("ConnectionStringName") { }

Secondly, this might just be you editing your code before you post, that name needs to match the name in the config file:

<add name="ConnectionStringName" providerName="System.Data.SqlClient" connectionString="...." />

Finally, you likely need to change your connection string to use standard SQL Server format and not EF format. So it will probably look something like this:

Data Source=LNODA-PC;Initial Catalog=Dashboard;Persist Security Info=True;User Id=XXXX;Password=XXXXXX;MultipleActiveResultSets=True;


来源:https://stackoverflow.com/questions/23914658/owin-oauth-provider-the-entity-type-identityuser-is-not-part-of-the-model-for-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!