开发者

Linq to SQL many to many Relationships - Insert Update & Delete

I have a database that relies on a bunch of Many-to-Many and rather than denormalizing the whole database (which is quite large) I wou开发者_Go百科ld like to know if there is a SIMPLE way of implementing Many-to-Many Relationships using LINQ-to-SQL Yet...

Everywhere I look I find articles on HOW Difficult It is, or A Simple Workaround that is actually "NOT" Simple. But all the articles I have been able to locate are pretty dated, using asp.net 3.5.

Should I just Create a Stored Procedure and then Drag it into the .DBML file as a method?

So I guess my question is:

Is there any new way to implement many-to-many using Linq-to-Sql in ASP.NET 4.0 along with MVC 3.


Examples of usage in my Project:

Linq to SQL many to many Relationships - Insert Update & Delete

In the finished model, there will be Other Tables linked to the Many-to-Many Tables (i.e. EventAddress, EventUrl, VipAddress, VipPicture, GuestAddress, GuestPhone, GuestEmail, etc...)

So you can see when this would be a pain in the a$$ to denormalize.

Thank you, Tim


Have you considered using Entity Framework? It handles m:n relationships nicely. In your case the EmployeeAddress table would be abstracted away as a list of addresses on your Employee object. It is also my impression that linq to sql isn't really a priority for Microsoft, EF Is. I understand if you do not wish to convert an existing project, but for new projects EF4 would probably be a better fit.


LINQ to SQL will always map directly to the structure of the database. If your database has all of those junction tables, then they will be in your LINQ to SQL model - period.


Although you can map many-to-many relationships in both LINQ to SQL and LINQ to Entities, LINQ to Entities allows a direct mapping of many-to-many relationships with no intermediary class, while LINQ to SQL requires that an intermediary class map one-to-many to each of the classes that are party to the many-to-many relationship.

link to the quote above - http://msdn.microsoft.com/en-us/library/cc161164.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜