Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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/0/asp.net-mvc/16.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# 类型或命名空间名称';用户';找不到(是否缺少using指令或程序集引用?_C#_Asp.net Mvc_Asp.net Identity - Fatal编程技术网

C# 类型或命名空间名称';用户';找不到(是否缺少using指令或程序集引用?

C# 类型或命名空间名称';用户';找不到(是否缺少using指令或程序集引用?,c#,asp.net-mvc,asp.net-identity,C#,Asp.net Mvc,Asp.net Identity,在尝试修复“无键定义错误”时,我在此处找到了修复方法(选项2答案): 在继承IdentityDbContext类时,我发现自己出现以下错误。所有参数都显示为未找到。我包括了我的“使用”列表,以查看是否缺少一个我不知道的参数。我感到困惑,因为我认为我需要的“使用”已被使用。帮助 using IdentitySample.Models; using Microsoft.AspNet.Identity.EntityFramework; using System; using System.Colle

在尝试修复“无键定义错误”时,我在此处找到了修复方法(选项2答案):

在继承IdentityDbContext类时,我发现自己出现以下错误。所有参数都显示为未找到。我包括了我的“使用”列表,以查看是否缺少一个我不知道的参数。我感到困惑,因为我认为我需要的“使用”已被使用。帮助

using IdentitySample.Models;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Web;

namespace FlavorPing.Models
{
    public class FlavorPingContext : IdentityDbContext<User, Role, int, UserLogin, UserRole, UserClaim>
    {

        public FlavorPingContext() : base("name=FlavorPingContext")
        {
        }

        public System.Data.Entity.DbSet<FlavorPing.Models.Merchant> Merchants { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.MenuItem> MenuItems { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.MerchantDetails> MerchantDetails { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.Follower> Followers { get; set; }

        public System.Data.Entity.DbSet<FlavorPing.Models.FollowerMenuItemMerchant> FollowerMenuItemMerchants { get; set; }

        public DbSet<UserLogin> UserLogins { get; set; }
        public DbSet<UserClaim> UserClaims { get; set; }
        public DbSet<UserRole> UserRoles { get; set; }


         protected override void OnModelCreating(DbModelBuilder builder) {
        // Primary keys
        builder.Entity<Follower>().HasKey(q => q.FollowerID);
        builder.Entity<MenuItem>().HasKey(q => q.MenuItemID);
        builder.Entity<Merchant>().HasKey(q => q.MerchantID);
        builder.Entity<FollowerMenuItemMerchant>().HasKey(q => 
            new { 
                q.FollowerID, q.MenuItemID, q.MerchantID
            });

        // Relationships
        builder.Entity<FollowerMenuItemMerchant>()
            .HasRequired(t => t.Follower)
            .WithMany(t => t.FollowerMenuItemMerchants)
            .HasForeignKey(t => t.FollowerID);

        builder.Entity<FollowerMenuItemMerchant>()
            .HasRequired(t => t.MenuItem)
            .WithMany(t => t.FollowerMenuItemMerchants)
            .HasForeignKey(t => t.MenuItemID);

        builder.Entity<FollowerMenuItemMerchant>()
        .HasRequired(t => t.Merchant)
        .WithMany(t => t.FollowerMenuItemMerchants)
        .HasForeignKey(t => t.MerchantID);


        builder.Conventions.Remove<PluralizingTableNameConvention>();
        builder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

        // Configure Asp Net Identity Tables
        builder.Entity<User>().ToTable("User");
        builder.Entity<User>().Property(u => u.PasswordHash).HasMaxLength(500);
        builder.Entity<User>().Property(u => u.Stamp).HasMaxLength(500);
        builder.Entity<User>().Property(u => u.PhoneNumber).HasMaxLength(50);

        builder.Entity<Role>().ToTable("Role");
        builder.Entity<UserRole>().ToTable("UserRole");
        builder.Entity<UserLogin>().ToTable("UserLogin");
        builder.Entity<UserClaim>().ToTable("UserClaim");
        builder.Entity<UserClaim>().Property(u => u.ClaimType).HasMaxLength(150);
        builder.Entity<UserClaim>().Property(u => u.ClaimValue).HasMaxLength(500);
    }


    }
}
使用IdentitySample.Models;
使用Microsoft.AspNet.Identity.EntityFramework;
使用制度;
使用System.Collections.Generic;
使用System.Data.Entity;
使用System.Data.Entity.ModelConfiguration.Conventions;
使用System.Linq;
使用System.Web;
名称空间ping.Models
{
公共类上下文:IdentityDbContext
{
public-FlavorPingContext():base(“name=FlavorPingContext”)
{
}
public System.Data.Entity.DbSet{get;set;}
public System.Data.Entity.DbSet MenuItems{get;set;}
public System.Data.Entity.DbSet MerchantDetails{get;set;}
public System.Data.Entity.DbSet Followers{get;set;}
public System.Data.Entity.DbSet followermenuitemchants{get;set;}
公共数据库集用户登录名{get;set;}
公共DbSet UserClaims{get;set;}
公共数据库集用户角色{get;set;}
模型创建时受保护的覆盖无效(DbModelBuilder builder){
//主键
builder.Entity().HasKey(q=>q.FollowerID);
builder.Entity().HasKey(q=>q.MenuItemID);
builder.Entity().HasKey(q=>q.MerchantID);
builder.Entity().HasKey(q=>
新{
q、 FollowerID,q.MenuItemID,q.MerchantID
});
//关系
builder.Entity()
.HasRequired(t=>t.Follower)
.WithMany(t=>t.FollowerNuitemMerchants)
.HasForeignKey(t=>t.FollowerID);
builder.Entity()
.HasRequired(t=>t.MenuItem)
.WithMany(t=>t.FollowerNuitemMerchants)
.HasForeignKey(t=>t.MenuItemID);
builder.Entity()
.HasRequired(t=>t.Merchant)
.WithMany(t=>t.FollowerNuitemMerchants)
.HasForeignKey(t=>t.MerchantID);
builder.Conventions.Remove();
builder.Conventions.Remove();
//配置Asp网络标识表
builder.Entity().ToTable(“用户”);
builder.Entity().Property(u=>u.PasswordHash).HasMaxLength(500);
builder.Entity().Property(u=>u.Stamp).HasMaxLength(500);
builder.Entity().Property(u=>u.PhoneNumber).HasMaxLength(50);
builder.Entity().ToTable(“角色”);
builder.Entity().ToTable(“用户角色”);
builder.Entity().ToTable(“UserLogin”);
builder.Entity().ToTable(“UserClaim”);
builder.Entity().Property(u=>u.ClaimType).HasMaxLength(150);
builder.Entity().Property(u=>u.ClaimValue).HasMaxLength(500);
}
}
}

你真的有一个名为User of type IdentityUser的类吗?是的,这是Identity框架的一部分。我想我应该更清楚,我想知道你是否在做一个自定义的User实现。如果不是,我想你不需要实体的builder代码块,试着注释一下。另外,我认为它是ApplicationUser不是User…如果没有看到更多的实现,很难说。哦,好的,我知道你现在要去哪里。我会处理这个问题。你真的有一个名为User of type IdentityUser的类吗?是的,这是身份框架的一部分。我想我应该更清楚一些,我想知道你是否在自定义实现用户与否。如果不是,我认为您不需要实体的生成器代码块,请尝试注释。此外,我认为这是应用程序用户不是用户…如果没有看到更多的实现,很难说。哦,好的,我知道您现在要做什么了。我将继续努力。