实体框架。获取填充了部分属性的实体 [英] Entity Framework. Get entity with a part of properties filled

查看:72
本文介绍了实体框架。获取填充了部分属性的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我需要知道如何获取实体,但只知道属性的一部分,而不是整个实体。我曾经调用 DbContext.Set< tentity>()。QuerySql(),但它无法构建一个合适的实体,因为它需要 ALL 内部数据中的实体属性读者。如何只获得部分实体?

Hi! I need to know how to fetch entities, but only with a part of properties, not the whole entity. I used to invoke DbContext.Set<tentity>().QuerySql(), but it fails to construct a proper entity since it needs ALL the entity properties in an internal data reader. How to get only partial entities?

推荐答案

你没有。在EF中,您只能将存储在数据库中的整个实体重新补充到DbContext定位器中。



您可以使用投影来获取您需要复制到另一个中的属性对象,但数据库仍将返回整个实体记录,DbContext仍将跟踪返回的实体的每个属性。
You don't. In EF you only get the entire entity stored in the database re-hydrated in the DbContext tacker.

You can use projection to get just the properties you need copied into another object, but the database is still going to return the entire entity record and the DbContext is still going to track every property of the entity that came back.


这篇关于实体框架。获取填充了部分属性的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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