Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在我的实体框架项目中使用标识框架_C#_Asp.net_Entity Framework_Asp.net Identity - Fatal编程技术网

C# 在我的实体框架项目中使用标识框架

C# 在我的实体框架项目中使用标识框架,c#,asp.net,entity-framework,asp.net-identity,C#,Asp.net,Entity Framework,Asp.net Identity,我正在尝试让identity framework在我的实体框架项目中工作 到目前为止,我已经创建了一组表,并且能够通过C#代码更新这些表。我现在需要让identity framework正常工作,以便将我的表链接到用户 我已为标识创建了上下文,但不断收到错误: 实体类型IdentityUser不是当前上下文模型的一部分 我通过创建一个MVC项目创建了这些表,因为这是我唯一能解决问题的方法 我的上下文类如下所示: public class SecurityContext : IdentityDbC

我正在尝试让identity framework在我的实体框架项目中工作

到目前为止,我已经创建了一组表,并且能够通过C#代码更新这些表。我现在需要让identity framework正常工作,以便将我的表链接到用户

我已为标识创建了上下文,但不断收到错误:

实体类型IdentityUser不是当前上下文模型的一部分

我通过创建一个MVC项目创建了这些表,因为这是我唯一能解决问题的方法

我的上下文类如下所示:

public class SecurityContext : IdentityDbContext
我试图将默认上下文更改为从IdentityDbContext继承,但遇到了相同的问题

任何帮助都将不胜感激

namespace LivingstoneWebAPI
{
    using Microsoft.AspNet.Identity.EntityFramework;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class LivingstoneWebNewEntities : IdentityDbContext<IdentityUser>
    {
        public LivingstoneWebNewEntities()
            : base("name=Test")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<Document> Documents { get; set; }
        public virtual DbSet<IPRestriction> IPRestrictions { get; set; }
        public virtual DbSet<Organisation> Organisations { get; set; }

    }
}
namespace LivingstoneWebAPI
{
使用Microsoft.AspNet.Identity.EntityFramework;
使用制度;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
公共部分类LivingstoneWebNewEntities:IdentityDbContext
{
公共生活东京新实体()
:base(“名称=测试”)
{
}
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
抛出新代码FirstException();
}
公共虚拟数据库集文档{get;set;}
公共虚拟数据库集IPRestrictions{get;set;}
公共虚拟数据库集{get;set;}
}
}

您的上下文是否继承自
IdentityDbContext
IdentityDbContext
?您是否记得调用
base.OnModelCreating(modelBuilder)从您的
OnModelCreating
覆盖?我在问题中添加了我的代码。看起来您试图将ASP.NET标识与基于EDMX的上下文混合。这是一个问题,因为标识使用基于代码优先的上下文,这将是很多问题。