Asp.net mvc 实体框架和LINQ以及定义嵌套表的视图

Asp.net mvc 实体框架和LINQ以及定义嵌套表的视图,asp.net-mvc,linq,entity-framework,Asp.net Mvc,Linq,Entity Framework,我正在尝试获取一些视图,以便使用数据库集形成嵌套表EF 6,数据库中的视图上没有FK关系,因此无法轻松更改。如何创建实体框架/LINQ或模型,并加载嵌套表 这些类对应于视图 public partial class Product { public System.Guid UniqueID { get; set; } public string Product { get; set; } public string Licensee { get; set; } public string Sup

我正在尝试获取一些视图,以便使用数据库集形成嵌套表EF 6,数据库中的视图上没有FK关系,因此无法轻松更改。如何创建实体框架/LINQ或模型,并加载嵌套表

这些类对应于视图

public partial class Product
{
public System.Guid UniqueID { get; set; }
public string Product { get; set; }
public string Licensee { get; set; }
public string Supplier { get; set; }
public int SeatCount { get; set; }
public System.DateTime ExpiryDate { get; set; }
public System.DateTime IssueDate { get; set; }
// would like IQueryable <Component> components here I can map to a MultiSelectList
}
public Partial class Component
{
public System.Guid UniqueID { get; set; }
public System.Guid ProductID { get; set; }
public string Description;
}
公共部分类乘积
{
public System.Guid UniqueID{get;set;}
公共字符串乘积{get;set;}
公共字符串被许可方{get;set;}
公共字符串提供程序{get;set;}
public int SeatCount{get;set;}
public System.DateTime ExpiryDate{get;set;}
public System.DateTime IssueDate{get;set;}
//想要IQueryable组件在这里我可以映射到一个多选列表
}
公共部分类组件
{
public System.Guid UniqueID{get;set;}
public System.Guid ProductID{get;set;}
公共字符串描述;
}
在使用中,DbSet产品要么作为整个列表获取,要么重新限定为单个供应商,然后根据产品和日期进行分页和搜索过滤


如何将组件集合放入产品中?我一直在读有关Modeler和EF的文章,但从某种意义上讲,这不是wuite Make。EF似乎也不喜欢我在表之间添加关系,可能是因为它们是视图?

这将是一种效率低下的方法,但如果您绝对无法在实体之间获得外键,则可以使用a和group by

var query = from prod in Products
            join comp in Components on prod.UniqueID equals comp.ProductID into compGroup
            select new {
                Product= prod,
                Components = compGroup  //This will be an IEnumerable<Component>
            };
var query=来自产品中的产品
将prod.UniqueID等于comp.ProductID上的comp in组件加入COMPGOUP
选择新的{
产品=产品,
Components=compGroup//这将是一个IEnumerable
};

编辑edmx文件,将store:Type=“Viewss”更改为store:Type=“Tables”,然后可以添加关联并生成正确的对象。

我认为不在两个表之间添加外键引用是不可能的。。。ef如何知道我必须在不知道id的情况下为组件加载数据。。。内部查询将在此处工作…Th ef不允许我添加关系,单击“添加”而不执行任何操作,大多数用户将签出: