具有继承和 RIA 服务的实体框架模型

发布于 2024-08-27 01:29:06 字数 351 浏览 4 评论 0原文

我们有一个实体框架模型,其中有一些继承。

下面的例子不是实际的模型,只是为了表明我的观点......

假设

基类:Person 子类: Employee、Customer

数据库已生成,DomainService 已创建,我们可以获取数据:

lstCustomers.ItemsSource = context.Persons;
EntityQuery<Person> query = context.GetPeopleQuery().Take(4);
context.Load(query);

但是如何修改查询以仅返回 Customers ?

We have an entity framework model with has some inheritance in it.

The following example is not the actuall model, but just to make my point...

Let's say

Base class: Person
Child classes: Employee, Customer

The database has been generated, the DomainService has been created and we can get to the data:

lstCustomers.ItemsSource = context.Persons;
EntityQuery<Person> query = context.GetPeopleQuery().Take(4);
context.Load(query);

But how can I modify the query to only return Customers ?

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

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

发布评论

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

评论(1

烛影斜 2024-09-03 01:29:06

您是否已经尝试过以下操作:

context.GetPeopleQuery().OfType<Customer>().Take(4)

我可以想象这并没有达到所需的效果,因为 OfType 可能是在客户端进行评估的。

Have you already tried the following:

context.GetPeopleQuery().OfType<Customer>().Take(4)

I can imagine this doesn't have the required effect though, because the OfType is probably evaluated client-side..

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