Owin OAuth provider “The entity type IdentityUser

2020-07-30 02: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")
        {
        }
    }

标签: c# wif
1条回答
干净又极端
2楼-- · 2020-07-30 03:23

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;
查看更多
登录 后发表回答