返回“定制” LinqToEntitiesDomainService 中的实体而不将它们映射到数据库?

发布于 2024-12-09 05:40:45 字数 365 浏览 0 评论 0原文

(我搜索了很多,但还没有找到答案,也许根本不可能:/)

是否可以在 EDM 中创建根本不映射到任何数据库的实体(我从中生成了 DomainService) ,只是在 DomainService 和 Client 之间使用? 对于那些实体框架专家来说,这可能听起来很奇怪:)我的目标是使得可以仅返回实体的几个属性,而不是整个实体。 例如,我只需要用户的姓名和生日,而不关心其他 10-20 个属性。在这种情况下,复杂度较低的实体将是完美的,是否可以制作这些实体的“轻量级”版本并在同一个 DomainService 中使用它们? 或者对于这种简单的数据查询场景(在数据库之上使用 EF)还有其他建议吗? (或者也许只是不关心 2011 年的带宽并始终检索完整的实体?:)

谢谢, 巴林特

(I searched a lot and didn't find an answer yet, maybe it is not possible at all:/)

Is it possible to create entities in the EDM (from which I generated my DomainService) that are not mapped at all to any DB, just used instead between the DomainService and the Client?
It might sound wierd for those who are entity framework pros:) My goal is to make it possible to return for example only a few properties of an entity instead of the whole entity.
For example I need only the name and birthdate of a user, and I don't care about the other 10-20 properties. In this case a less complex entity would be perfect, is it possible to make these "lightweight" versions of the entities and use them in the same DomainService?
Or any other suggestions for this kind of simple data querying scenario, using EF on top of the DB?
(Or maybe just don't care about the bandwith in 2011 and retrieve full entities always? :)

Thanks,
Bálint

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

老旧海报 2024-12-16 05:40:45

您可以通过选择实体的多个属性来加载匿名类型,如下所示,

 var studentEnrolments = from s in db.Students
                                  select new { s.FirstMidName,s.Enrollments};
        var studentEnrolmentsList= studentEnrolments.ToList();
        foreach (var studentEnrolment in studentEnrolmentsList)
        {
           //do something here 
        }

http:// msdn.microsoft.com/en-us/library/bb738512.aspx

编辑..

 var studentEnrolments = from s in db.Students
                       select new Student{FirstMidName= s.FirstMidName, Enrollments=s.Enrollments};

You can load anonymous types by selecting sevaral properties of your entity like this,

 var studentEnrolments = from s in db.Students
                                  select new { s.FirstMidName,s.Enrollments};
        var studentEnrolmentsList= studentEnrolments.ToList();
        foreach (var studentEnrolment in studentEnrolmentsList)
        {
           //do something here 
        }

http://msdn.microsoft.com/en-us/library/bb738512.aspx

Edit..

 var studentEnrolments = from s in db.Students
                       select new Student{FirstMidName= s.FirstMidName, Enrollments=s.Enrollments};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文