Linq to Entity - 在列表模板 MVC 页面中时我可以访问模型中的另一个表吗
在项目模板解决方案(动态数据 Web 应用程序)中,我创建了模型,一切都很好。 - 获取表的列表,然后选择编辑等。
但是我的数据库具有仅包含伪造密钥的链接表 - 因此列表模板仅显示 fk 值
是否可以将主表中的行列表与基于 fk 的另一个表的检查结合起来?
更类似于 SQL 中的连接? 但使用 Linq2Entity 和 MetaModel?
下面是 List.aspx.cs - 这似乎将标准网格绑定到实体数据源,但这是根据 MVC 中的路由绑定到当前表。
但正如您所看到的,我需要通过模型查询人员、角色和链接表以获取其他字段,这样这将很有用。
PS 如果可能的话,想尝试将其保留在 LINQ2Entity 中 - 尝试 grok
我想做的自然的事情是开始派生新的 SQL 查询来检索值。 但这并不在这个习语中。
in the out of the project template solution (Dynamic Data Web Application), I have the model created and all is good. - Get the list of the tables, and the select edit etc.
But my database has linking tables that just contain forgien keys - so the list template just displays the fk value
Is there away to combine the list of the row in the primary table with an inspection of another table based on the fk?
More akin to a join in SQL? but using Linq2Entity and the MetaModel?
Below is the List.aspx.cs - this seems to bind the standard grid to the entitydatasource, but this is to the current table as per the route in the MVC.
But as you can see i need to go and query the Person, Role and Link table via the model to get the other fields so that this would be useful.
PS want to try and keep this in LINQ2Entity if possible -trying to grok
the natural thing that I want to do is start to spin off new sql queries to go and retrive the values. But this is not in this idiom.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过 dataContext
PS 查看您的代码来引用元模型,这在您的 sceanrio 中有效。 您可以从模型中获取表,然后检查模型中每个表返回的数据
有关 MetaModel 的 MSDN 文章
you can reference the metaModel via the dataContext
PS looked at your code and this works in your sceanrio. You can get the tables from the model then inspect the data returned for each table in the model
MSDN article on the MetaModel
从 Linq to Entities 模型中使用它也很有用 -
使用 dataContext - 您可以获得最有用的实际数据。
metaModel 允许访问 dataModel,它为您提供底层 ddl 类型信息
Uselful to use this as well from the Linq to Entities Model -
Using the dataContext - you can get the acutal data most useful.
The metaModel allows access to the dataModel which gives you the underlying ddl type information