本文介绍了Linq到SQL多对多关系没有第三类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据库中,我有以下表格:

In my database I have the following tables:


  • 客户(ID)

  • (ID)

  • CustomersOrders(CustomerID,OrderID)

客户类和订单表到订单类没有创建类CustomersOrders?

How do I map Customers table to Customers class and Orders table to Orders class without creating a class CustomersOrders?

推荐答案

这取决于你正在谈论的LINQ版本。

That depends on which LINQ version you're talking about.

如果您使用的是Entity Framework 4.0,除了ID之外,表中没有其他信息,那么您需要的内容应该已经生成。我相信Entity Framework 1.0也是如此。

If you're using Entity Framework 4.0 and you have no additional information in the table other than the IDs then what you are asking for should already be generated. I believe the same is true for Entity Framework 1.0.

LINQ to SQL是另一个故事。它从来没有处理过多对多的关系。您必须允许LINQ to SQL生成第三个表,然后在单独的文件中手动扩展部分类以隐藏第三个表。这是丑陋,但它的工作。这里有一系列的博文,详细说明了需要做什么:

LINQ to SQL is another story. It never handled Many-to-Many relationships well. You have to allow LINQ to SQL generate the third table and then extend the partial classes by hand in a separate file to mask away that third table. It's ugly but it works. Here's a series of blog posts that detail exactly what needs to be done:

这篇关于Linq到SQL多对多关系没有第三类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 00:34