Linq to Entity - 在列表模板 MVC 页面中时我可以访问模型中的另一个表吗

发布于 2024-07-08 11:28:38 字数 672 浏览 8 评论 0原文

在项目模板解决方案(动态数据 Web 应用程序)中,我创建了模型,一切都很好。 - 获取表的列表,然后选择编辑等。

但是我的数据库具有仅包含伪造密钥的链接表 - 因此列表模板仅显示 fk 值

表的图表

是否可以将主表中的行列表与基于 fk 的另一个表的检查结合起来?

更类似于 SQL 中的连接? 但使用 Linq2Entity 和 MetaModel?

下面是 List.aspx.cs - 这似乎将标准网格绑定到实体数据源,但这是根据 MVC 中的路由绑定到当前表。

但正如您所看到的,我需要通过模型查询人员、角色和链接表以获取其他字段,这样这将很有用。 vstudio

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

diagram of the table

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.
vstudio

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴者 2024-07-15 11:28:38

您可以通过 dataContext

MetaModel refMetaModel = MetaModel.GetModel(typeof(yourdataContextName));
MetaTable refMetaModel;
refMetaModel =  refMetaModel.GetTable("yourTableName");

PS 查看您的代码来引用元模型,这在您的 sceanrio 中有效。 您可以从模型中获取表,然后检查模型中每个表返回的数据

有关 MetaModel 的 MSDN 文章

you can reference the metaModel via the dataContext

MetaModel refMetaModel = MetaModel.GetModel(typeof(yourdataContextName));
MetaTable refMetaModel;
refMetaModel =  refMetaModel.GetTable("yourTableName");

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

怎言笑 2024-07-15 11:28:38

从 Linq to Entities 模型中使用它也很有用 -

使用 dataContext - 您可以获得最有用的实际数据。

metaModel 允许访问 dataModel,它为您提供底层 ddl 类型信息

//use the datacontext to get the underlying data
      using (brrdbEntities brr = new brr_dbEntities())
      {
          ObjectQuery<person> people = brr.person;
          IQueryable<string> names = from p in people select p.person_name;
          foreach (var name    in names)

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

//use the datacontext to get the underlying data
      using (brrdbEntities brr = new brr_dbEntities())
      {
          ObjectQuery<person> people = brr.person;
          IQueryable<string> names = from p in people select p.person_name;
          foreach (var name    in names)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文