相关疑难解决方法(0)

EF Code First具有多对多的自引用关系

我开始使用EF Code First和MVC,我有点难过.我有以下数据库结构(很抱歉,我不允许发布图片):

表 - 产品
表 - 相关产品

Products.ProductID上的1-Many - > RelatedProducts.ProductID
1 - Products.ProductID上的很多 - > RelatedProducts.RelatedProductID

基本上我有一个产品,可以有一系列与之相关的产品.它们保存在RelatedProducts表中,其中包含ProductID和相关产品的ProductID定义的关系,我将其命名为RelatedProductID.在我的代码中,我生成了以下类:

public class MyDBEntities : DbContext
{
    public DbSet<Product> Products { get; set; }
    public DbSet<RelatedProduct> RelatedProducts { get; set; }
}

public class Product
{
    public Guid ProductID { get; set; }
    public string Name { get; set; }
    public string Heading { get; set; }
    public string Description { get; set; }
    public decimal Price { get; set; } …
Run Code Online (Sandbox Code Playgroud)

many-to-many entity-framework-4 self-reference entity-framework-ctp5

9
推荐指数
1
解决办法
7259
查看次数

实体框架多对多问题

请帮助EF n00b设计他的数据库.我有几家公司生产多种产品,因此公司和产品之间存在多对多的关系.我有一个与他们相关的中间表,Company_Product.

每个公司/产品组合都有一个独特的SKU.例如,Acme小部件具有SKU 123,但Omega小部件具有SKU 456.我将SKU添加为Company_Product中间表中的字段.

EF生成了一个模型,该模型在公司和Company_Product表之间具有1:*关系,并且产品和Company_Product表之间具有1:*关系.我真的想要:公司和产品之间的关系.但是,最重要的是,无法直接从模型访问SKU.

我是否需要将SKU放在自己的表中并编写连接,还是有更好的方法?

many-to-many entity-framework

8
推荐指数
1
解决办法
4206
查看次数

如何通过实体框架访问多对多表?asp.net

如何通过EF读取多对多表格?我不知道如何使用多对多表。比方说,Product_Category在那里得到了ProductIDCategoryID

我怎样才能通过例如它

using(Entities db = new Entities)
{
    /* cant access these here.. */}
Run Code Online (Sandbox Code Playgroud)

方法??但是Product_Category,我可以访问,但无法访问其ProductIDCategoryID

我想列出每个产品,例如在哪里Product_Category.CategoryID == Category.ID

我以前从未使用过多对多表,因此,我欣赏一些简单的示例,说明如何通过asp.net中的EF访问它们。

谢谢

c# sql asp.net many-to-many entity-framework

1
推荐指数
1
解决办法
6042
查看次数