使用LINQ to SQL建模ASP.NET MVC一个多一对多的关系 [英] Modeling a many-to-many relationship in ASP.NET MVC using LINQ to SQL

查看:107
本文介绍了使用LINQ to SQL建模ASP.NET MVC一个多一对多的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读和观看有关MVC视频,我开始变得有点困惑。简单的教程过于简单,他们似乎只涉及单个数据库表。 Whoopty斗!

I've been reading and watching videos about MVC and I'm starting to get a little confused. The simple tutorials are far too simple and they seem to only involve a single database table. Whoopty doo!

的高级教程承担了大量的知识是present,我有以下这些烦恼。更何况,有15个方法来模拟你的数据库,并没有人愿意解释为什么他们做这样或那样的方式。

The advanced tutorials assume a lot of knowledge is present and I have trouble following those. Not to mention, there are 15 ways to model your database and nobody wants to explain why they do it this way or that way.

所以,我在找一个简单的教程或者你会去什么样过程中,通过设计,涉及许多一对多的关系,一个简单的CRUD应用程序的说明,解释如下。我可能没有提供足够的信息,以便随时请求更新。

So, I'm looking for a simple tutorial or explanation of what process you would go through to design a simple CRUD application that involves a many-to-many relationship, explained below. I may not have provided enough information so feel free to request updates.

更新:
我会希望看到一个LINQ to SQL的解决方案。

Updates: I would be interested in seeing a Linq To Sql solution.

我走过的NerdDinner PDF去了,我的模型有可能比他有点不同。我想用我的膳食和我的主料多对一对多的关系。他只是采用了1对多的与他的晚餐和回函。此外,他还从来没有说明他是如何附着在回函给他的晚餐模式。这基本上是我遇到的问题。为什么我的膳食模式不包含配料清单?我已经制定适当的外键。我不知道在哪里,我怎么会设定,让我能够通过膳食模式访问成分,如果我想打印出来的细节视图或者什么的。

I went through the nerddinner PDF and my model has to be a little different than his. I want a many-to-many relationship with my Meal and my Ingredients. He just uses a 1-to-many with his Dinner and RSVPs. Also, he never shows how he attached the RSVPs to his Dinner model. This is essentially the problem I'm having. Why is it that my Meal model does not contain a list of Ingredients? I have the proper foreign keys in place. I'm not sure where or how I would set it up so that I can access the ingredients through the Meal model if I wanted to print them on the details view or something.


  • 标识

  • 标题

  • 说明


  • 标识

  • 名称


  • Id_Meal

  • Id_Ingredient

推荐答案

我发现的唯一的解决办法是使用PLINQ。这是不是就我虽然知道完美。

The only solution I found was using PLINQ. It isn't perfect as far as I know though.

我使用了PLINQ方法手动:的的http://www.$c$cproject.com/KB/linq/linq-to-sql-many-to-many.aspx

I use the "PLINQ method" manually: http://www.codeproject.com/KB/linq/linq-to-sql-many-to-many.aspx

我同意,虽然,我讨厌一遍又一遍写所有code。这不是一个干净的解决方案。

I agree though, I hate writing all that code over and over again. It isn't a "clean" solution.

这篇关于使用LINQ to SQL建模ASP.NET MVC一个多一对多的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆