本文介绍了Owin OAuth的提供商QUOT;实体类型IdentityUser是不是该机型为当前上下文和部分地方;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  UserManagerFactory =()=>新的UserManager&所述; IdentityUser>(新UserStore&所述; IdentityUser>()); 
OAuthOptions =新OAuthAuthorizationServerOptions
{
TokenEndpointPath =新PathString(/令牌),
提供商=新ApplicationOAuthProvider(PublicClientId,UserManagerFactory),
AuthorizeEndpointPath =新PathString (/ API / AccountOwin / ExternalLogin)
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp =真
};



从中IdentityUser,UserStore comesform实体框架。



我想用我的数据库,而不是本地数据库,我产生从我创造了他们在我的自定义数据库的本地数据库表和
生成的剧本,但是当我浐下面的行中的DB背景:

  UserManagerFactory =()=>新的UserManager&所述; IdentityUser>(新UserStore&所述; IdentityUser>(新MyCustomDBEntities())); 



在哪里MyCustomDBEntities是实体框架我的自定义数据库(EDMX)
我得到的以下错误:
的实体类型IdentityUser是不是该机型为当前上下文的一部分。



我做错了吗? ?
我应该创建自己的UserManager

 公共类MyCustomDBEntities:IdentityDbContext< IdentityUser> 
{
公共MyCustomDBEntities()
:基地(NAME =的connectionStringName)
{
}
}


解决方案

我怀疑问题是与您的连接字符串。首先,上下文的构造只需要有连接字符串的名字,所以你可以把它改成这样:

 公共MyCustomDBEntities():基地(的connectionStringName){} 

其次,这也可能只是您编辑您的代码发布前,该名称需要在名称中的配置文件相匹配:

 <添加名称=的connectionStringName的providerName =System.Data.SqlClient的的connectionString =.../> 



最后,你可能需要改变你的连接字符串使用标准的SQL Server格式,而不是EF格式。因此,它可能会是这个样子:

 数据源= LNODA-PC;初始目录=仪表盘;坚持安全信息= TRUE ;用户ID = XXXX;密码= XXXXXX; MultipleActiveResultSets = TRUE; 


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 andI 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")
        {
        }
    }
解决方案

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;

这篇关于Owin OAuth的提供商QUOT;实体类型IdentityUser是不是该机型为当前上下文和部分地方;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 08:32