如何限制包含在实体框架中 [英] How to limit include in entity framework

查看:87
本文介绍了如何限制包含在实体框架中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用实体lamda表达式来检索数据。

现在我的一个表有其他5个子实体。



我尝试过:



我使用。包括来检索子实体数据。

但是我不想要检索子实体的所有数据。

我想要所有5个子实体中只有2-3列。

任何人都可以帮助我吗?

解决方案

最好的选择我已发现是使用ViewModel。

ViewModel可用于指定表字段的子集,可以从您的控制器填充



请尝试以下链接以获取更多信息信息和教程;

第3部分:视图和ViewModels | Microsoft Docs [ ^ ]

MVC中的通用ViewModels [ ^ ]

如何在Asp.Net MVC中使用ViewModel示例 - Tutlane [ ^ ]



种类此致

Hi,

I am using entity lamda expression to retrieve the data.
Now my one table has other 5 child entities.

What I have tried:

I am using .Include to retrive child entity data.
But i don`t want to retrive all data of child entities.
I want only 2-3 columns from all 5 child entities.
Can any one please help me is that possible?

解决方案

The best option I have found is to use a ViewModel.
A ViewModel can be used to specify a subset of the table fields and can be populated from your controller

Try the following links for additional information and tutorials;
Part 3: Views and ViewModels | Microsoft Docs[^]
Generic ViewModels in MVC[^]
How to Use ViewModel in Asp.Net MVC with Example - Tutlane[^]

Kind Regards


这篇关于如何限制包含在实体框架中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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