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