我是否应该从模型中删除所有继承才能使用 ria 服务?

发布于 2024-08-27 01:20:31 字数 1587 浏览 3 评论 0原文

我之前曾就此发布过一些问题,但情况有所不同。

因此,考虑我们模型的一小部分:

  • Person
    • 客户
    • 员工
    • 配偶

Person 是基类,有 3 个继承自它的类。

这 4 个在我们的设计中非常核心,并且与许多其他实体有联系。 我可以通过删除来解决我在 ria-services 中遇到的所有问题 继承,但这确实会增加模型的复杂性。

我遇到的第一个问题是我无法查询客户、员工或配偶,但有人给了我一个解决方案,就是在 DomainService 中添加这样的内容:

    public IQueryable<Employee> GetEmployees()
    {
        return this.ObjectContext.People.OfType<Employee>();
    }

    public IQueryable<Customer> GetCustomers()
    {
        return this.ObjectContext.People.OfType<Customer>();
    }

    public IQueryable<Spouse> GetSpouses()
    {
        return this.ObjectContext.People.OfType<Spouse>();            
    }

接下来我尝试了一些对我来说似乎很正常的东西:

var employee = new Employee()
{
    //.... left out to reduce the length of this question 
};

var spouse = new Spouse() 
{
    //.... left out to reduce the length of this questions
};

employee.Spouse = spouse;

context.People.Add(spouse);
context.People.Add(employee);
context.SubmitChanges();

然后我得到以下异常:

无法检索实体集 派生实体类型“配偶”。使用 EntityContainer.GetEntitySet(Type) 到 获取基本实体的实体集 输入“人”。

即使配偶已经在数据库中, 我首先检索它,我得到类似的异常。

另请注意,由于某种原因,在某些地方使用“Person”而不是“People”......

那么我该如何解决这个问题,我做错了什么 当我使用具有继承功能的 ria 服务时,我会不断遇到困难吗?

我在网上找到了一些参考资料,都说它有效,然后是一些 DomainService 他们据称更改了某些内容但没有详细信息的代码...

我正在使用 VS2010 RC1 + Silveright 4

注意:在所有 MIX 会话中神奇地工作的数据源窗口对我来说不起作用。它从不显示任何内容。

I've posted some questions on this before, but it's different.

So consider a small portion of our model:

  • Person
    • Customer
    • Employee
    • Spouse

Person is the base class which has 3 classes that inherit from it.

These 4 are very central in our design and link to many other entities.
I could solve all the problems I'm experiencing with ria-services by removing
the inheritance but that would really increase the complexety of the model.

The first problem I experienced was that I couldn't query for Customers, Employees or Spouses, but someone gave me a solution, which was to add something like this to the DomainService:

    public IQueryable<Employee> GetEmployees()
    {
        return this.ObjectContext.People.OfType<Employee>();
    }

    public IQueryable<Customer> GetCustomers()
    {
        return this.ObjectContext.People.OfType<Customer>();
    }

    public IQueryable<Spouse> GetSpouses()
    {
        return this.ObjectContext.People.OfType<Spouse>();            
    }

Next I tried something that seemed very normal to me:

var employee = new Employee()
{
    //.... left out to reduce the length of this question 
};

var spouse = new Spouse() 
{
    //.... left out to reduce the length of this questions
};

employee.Spouse = spouse;

context.People.Add(spouse);
context.People.Add(employee);
context.SubmitChanges();

Then I get the following exception:

Cannot retrieve an entity set for the
derived entity type 'Spouse'. Use
EntityContainer.GetEntitySet(Type) to
get the entity set for the base entity
type 'Person'.

Even when the spouse is already in the database,
and I retreive it first I get similar exceptions.

Also note that for some reason in some places "Persons" is used instead of "People"...

So how do I solve this problem, what am I doing wrong
and will I keep running into walls when using ria services with inheritance?

I found some references on the web, all saying it works and then some DomainService
code in which they suposedly changed something but no details...

I'm using VS2010 RC1 + Silveright 4

Note: The data sources window that magically works in all the MIX sessions does not work for me... it never displays anything

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

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

发布评论

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

评论(1

萌无敌 2024-09-03 01:20:31

此行为是由于 RC1 中的错误造成的。更详细的讨论请参见 http://forums.silverlight.net /forums/p/169599/384514.aspx#384514

RC1 没有已知的解决方法,但您显示的层次结构在 RC2 中应该可以正常工作。该错误集中在使用派生类型(EntityRef 和 EntityCollection)的关联上,因此我怀疑配偶关联是在您的场景中触发该错误的原因。

关于“Persons”与“People”——实体集的名称选择来自 EF 对实体名称的复数形式。客户端上的查询名称来自 DomainService 中相应的查询名称,这意味着您可以根据需要公开公共 IQueryable GetPeople()。

This behavior was due to a bug in the RC1. It is discussed in more detail at http://forums.silverlight.net/forums/p/169599/384514.aspx#384514.

There is no known workaround for RC1, but the hierarchy you show should work fine in RC2. The bug centered around associations using derived types (EntityRef and EntityCollection), so I suspect the Spouse association was what triggered the bug in your scenario.

Regarding "Persons" v. "People" -- the name selection for the entity set comes from EF's pluralization for the entity names. The name of the query on the client comes from the corresponding query name in the DomainService, meaning you could expose a public IQueryable GetPeople() if you wanted.

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