views:

77

answers:

2

Hello everyone!

It could be the question about Entity Framework (WCF RIA domain model is based on it) but I'm not sure...

So I have Silverlight UI (MVVM) + WCF RIA domain services + Entity Framework on server side.

I have data Entities: Room -> Hotel (parent entity) <- RoomTypes plus Room has a reference to room type (so Room can be e.g. Single or Twin or Double etc). And one Hotel contains a set of Room Types used in this hotel.

Problem - on UI side I created user control - Room editor. There is I have text boxes (there is no any problem with text boxes and data binding) and also there is I have comboBox - to edit Room Type of Room. I can't figure out what is correct way to work this way... Please help me with it!

What I have now - I tried to load Hotels with Room types (in domain metadata - via [Include] attribute and plus this.ObjectContext.Hotels.Include("RoomTypes") in WCF RIA server side domain class) and in comboBox bind it to the room types list. But! If i choose some room type where was an exception - "Entity 'RoomType' cannot be attached to this EntityContainer because it is already attached to another EntityContainer."... Hotel is loaded by separate domain service and room types (in the User Control) is loaded by own domain service. How can I solve it?

Thanks in advance!

+1  A: 

My second point in this post covers the issue you're running into.

http://blogs.msdn.com/b/kylemc/archive/2010/06/18/combobox-sample-for-ria-services.aspx

To correctly set up this association, you need to make sure you're loading Rooms and RoomTypes (specifically the RoomTypes you use in the ComoboBox) in the same DomainContext. Along those lines, you may also find my third point in that post helpful when dealing with asynchronously populating lookups.

Kyle

Kyle McClellan
A: 

Einarsson, Kyle - thank you for you answers!

I'm still loading Hotels with the list of Room Types but yesterday I decided to move to single domain data source and it seems like this is what i'm searching for. It allows me to store all entities (related with Hotel) into one DDS - i.e. one Domain Context for all entities. Now the single DDS responsible for loading, saving of all entities, related with Hotel and it works (I just have to fix some issues related with data binding)

this is my first experience in WCF RIA :)

And again - thank you for your answers!

MagicMax