直接使用EntitySet?

发布于 2024-10-08 23:32:34 字数 236 浏览 0 评论 0原文

我正在尝试了解 Entity Framework 4 中存在的所有类。(到目前为止)我唯一感到困惑的是 EntitySet。在我的 .edmx 文件生成的 C# 代码中,从未提及 EntitySet,仅在 XML 文件(.csdl、.msl、.ssdl)中提及。

ObjectSet 似乎是 EntitySet 的包装器(尽管它也将 EntitySet 公开为公共属性。)是否存在我将直接使用 EntitySet 的情况?

I'm trying to wrap my head around all the classes present in Entity Framework 4. The only one that I'm confused by (so far) is EntitySet. EntitySets are never mentioned anywhere in the generated C# code from my .edmx files, only in the XML files (.csdl, .msl, .ssdl).

ObjectSet seems to be a wrapper around EntitySet (although it also exposes the EntitySet as a public property.) Are there any cases where I will be directly working with EntitySets?

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

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

发布评论

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

评论(1

救星 2024-10-15 23:32:34

来自 MSDN

给定类型及其子类型的实体的逻辑容器。实体集映射到数据库中的表。

本质上,它是 CSDL 讨论 - 关于对象映射到哪个实体“集”。

您无需担心 - 您将使用 ObjectSet

var orders = ctx // ObjectContext
             .Orders // ObjectSet<Order>
             .SingleOrDefault(); // Order

获得额外提示 - 如果可能,请使用 IObjectSet; 以促进单元测试(实现模拟测试 - 例如内存中的静态列表)。

From MSDN:

A logical container for entities of a given type and its subtypes. Entity sets are mapped to tables in a database.

Essentially, it's CSDL talk - as to which "set" of entities the objects are mapped to.

You don't need to worry about it - you'll be working with ObjectSet<T>:

var orders = ctx // ObjectContext
             .Orders // ObjectSet<Order>
             .SingleOrDefault(); // Order

For a bonus tip - if possible, use IObjectSet<T> to facilitate unit testing (implement a mock one - e.g an in-memory static list).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文