0
votes

Framework: .NET 4, Entity Framework 4, Silverlight 4, RIA services

I'm trying to split my Entity Framework model into two domain service classes. The model is not complex - several tables. So I have created a single Entity Framework model.

I'd like to create two Domain service classes - each accessing a subset of the complete EF model. I first create a single domain service class. RIA generates the DomainContext in the SL4 application based on the Domain Service. However, when I add a second Domain Service class, RIA does not generate any of the Domain Contexts (so I am unable to use even the first one).

(Note: both domain services have EnableClientAccess attribute set and both have at least one query.)

Why are the contexts not generated and how can this be solved? Am I missing something? Can RIA generate the contexts for two different domain services that use the same entity framework model?

3
Have you rebuild your solution after adding DomainContext? Does the EF sets rely on eachother?mike
Yes, there are shared entities, however I don't need to use both contexts at the same time (meaning that I don't mean to mix entities from different contexts). But there are entities (db tables) that are used in both domain services.Kornelije Petak
Of course I have rebuilt. And I get that error: "Entity types cannot be shared across DomainServices." But I am not sure how to solve this.Kornelije Petak

3 Answers

0
votes

Not a RIA expert but I'm wondering if you are trying to pass an entity that was retrieved in one of your services to the other service. If you were working directly with EF, not through RIA, you would have a problem in the case where you retrieved using one objectcontext and then tried to pass the entity to another objectcontext. In the "working directly with EF" scenario, you have to first detach the entity from the context that pulled it from the database before you can attach it to the other context. So if that's what you are doing in your RIA app, it might be the same problem. The entity would need to be detached from the first service. I can't tell you how to do that as I haven't used RIA services in a long time. Hopefully this will point you in a useful direction though.

0
votes

It's seem like your entity is exposed by 2 DomainService, e.g. your have entity name Company and you have method that return Company in both of your Domain Service:

public class DomainServiceA
{
    public IQueryable<Company> MethodA() { .. }
}

public class DomainServiceB
{
    public IQueryable<Company> MethodB() { .. }
}
0
votes

Yea from what I've seen there's not really a super simple way to just make it work... I usually just put it all in one domain service because of this :-/ Not ideal but maybe it'll change in a release or so... Otherwise I just create specific DTO's for each domainservice implementation and use those :-/

Here's a few other suggestions that might help

http://forums.silverlight.net/t/146340.aspx/1

http://forums.silverlight.net/t/111058.aspx/1

Otherwise the only way I think you could do it is to create two different EF models over the subset of data you are representing in different assemblies and expose them that way..