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# 在EntityFramework CodeFirst中过滤DbSet_C#_Asp.net Mvc_Entity Framework_Dbcontext - Fatal编程技术网

C# 在EntityFramework CodeFirst中过滤DbSet

C# 在EntityFramework CodeFirst中过滤DbSet,c#,asp.net-mvc,entity-framework,dbcontext,C#,Asp.net Mvc,Entity Framework,Dbcontext,这是应用程序用户: public class ApplicationUser : IdentityUser<long> { public string Firstname { get; set; } public string Lastname { get; set; } public UserTypes Type { get; set; } public string FullName { get { return $"{Firstname ?? "

这是应用程序用户:

public class ApplicationUser : IdentityUser<long>
{
    public string Firstname { get; set; }
    public string Lastname { get; set; }
    public UserTypes Type { get; set; }
    public string FullName { get { return $"{Firstname ?? ""} {Lastname ?? ""}".Trim(); } }
}
public virtual DbSet<Provider> Providers{get;set;}
public virtual DbSet<Supporter> Supporters{get;set;}
现在在
ApplicationDbContext
中,我希望在ApplicationUser旁边有这些
DbSet
s:

public class ApplicationUser : IdentityUser<long>
{
    public string Firstname { get; set; }
    public string Lastname { get; set; }
    public UserTypes Type { get; set; }
    public string FullName { get { return $"{Firstname ?? ""} {Lastname ?? ""}".Trim(); } }
}
public virtual DbSet<Provider> Providers{get;set;}
public virtual DbSet<Supporter> Supporters{get;set;}
公共虚拟数据库集提供程序{get;set;}
公共虚拟数据库集{get;set;}
哪个
DbSet
应该返回
ApplicationUsers
,其
用户类型等于2(例如)

公共类ApplicationDbContext:IdentityDbContext
{
公共应用程序DBContext(DbContextOptions选项)
:基本(选项)
{
}
公共应用程序上下文()
:base()
{
}
公共虚拟IEnumerable提供程序
{
得到
{
返回(IEnumerable)Users.Where(z=>z.Type==UserTypes.Provider).AsEnumerable();
}
}
}

UserTypes的属性是什么?@H.Herzl这是一个枚举
{Normal=1,Provider=2,Supporter=3}
您尝试过这个吗?var query=dbContext.Providers.Where(item=>item.Type==UserTypes.Provider.ToList();这是我一直做的事。我想让它成为一个具有自己独特属性(类似于sql中的视图)的虚拟数据库集。我不明白,您是否尝试过该代码但不起作用?