简体   繁体   English

为了使用ria服务,是否应该从模型中删除所有继承?

[英]Should I remove all inheritance from my model in order to work with ria services?

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. Person是具有3个继承自其的类的基类。

These 4 are very central in our design and link to many other entities. 这4个在我们的设计中非常重要,并与许多其他实体链接。 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. 我可以通过删除继承来解决ria服务遇到的所有问题,但这确实会增加模型的复杂性。

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: 我遇到的第一个问题是我无法查询客户,雇员或配偶,但是有人给了我一个解决方案,那就是在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'. 使用EntityContainer.GetEntitySet(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? 那么我该如何解决这个问题,我在做什么错?在使用带有继承的ria服务时,我会一直陷入困境吗?

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... 我在网上找到了一些参考资料,都说它可以正常工作,然后在其中的DomainService代码中他们改变了某些内容,但没有任何细节。

I'm using VS2010 RC1 + Silveright 4 我正在使用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 注意:神奇地在所有MIX会话中工作的数据源窗口对我而言不起作用...它从不显示任何内容

This behavior was due to a bug in the RC1. 此行为是由于RC1中的错误所致。 It is discussed in more detail at http://forums.silverlight.net/forums/p/169599/384514.aspx#384514 . 有关详细信息,请参见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. RC1没有已知的解决方法,但是您显示的层次结构在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. 该错误集中在使用派生类型(EntityRef和EntityCollection)的关联上,因此我怀疑是在您的场景中触发了该错误的是Spouse关联。

Regarding "Persons" v. "People" -- the name selection for the entity set comes from EF's pluralization for the entity names. 关于“人”与“人”-实体集的名称选择来自EF对实体名称的复数。 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. 客户端上的查询名称来自DomainService中的相应查询名称,这意味着您可以根据需要公开一个公共IQueryable GetPeople()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有继承和RIA服务的实体框架模型 - Entity Framework Model with inheritance and RIA Services 如何加载与RIA Services相关的所有项目? - How do I load all items in a relationship with RIA Services? .NET WCF RIA +服务; 能给我全部吗 - .NET WCF RIA + Services; Can I have it all? 我可以通过RIA服务向我的实体添加可序列化的属性吗? - Can I add serializable properties to my Entities with RIA Services? 我应该在继承链中包含所有接口吗? - Should I include all the interfaces in the inheritance chain? 在WCF Ria服务中,是否可以其他连接到我的服务? 如果是,我如何禁止它 - In WCF Ria Services, is it possible to other to connect to my Service? If yes, how can I ban it 为什么继承不以我认为它应该工作的方式工作? - Why doesn't inheritance work the way I think it should work? 我应该对我的域服务进行授权吗? - Should i do authorization on my Domain Services? 我应该将服务注入我的MVC视图吗? - Should I inject services into my MVC views? 如何为移动和Silverlight前端在IIS上托管WCF RIA DataDomainService? - How should I Host my WCF RIA DataDomainService On IIS for a mobile and silverlight front end?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM