views:

465

answers:

1

I've got a database which has a table called m_AttentionFlags which references a primary key in m_PermissionCollections. I've built an EntityFramework model from this and created a DomainService.

Now using RIA on the client I have loaded the flags into the local context on initialization of a control:

var query = _context.GetM_AttentionFlagQuery(); 
_context.Load(query, OnGetM_AttentionFlag, null); 

Then I've wired up a button to add an m_PermissionCollection to a selected m_AttentionFlag.

if (lstSelected.SelectedItem != null) { 
if (!(lstSelected.SelectedItem is m_AttentionFlag)) 
{ 
return; 
} 
m_AttentionFlag flag = lstSelected.SelectedItem as m_AttentionFlag; 
m_PermissionCollection coll = new m_PermissionCollection(); //** 
flag.m_PermissionCollections = coll; //** 
_context.SubmitChanges(); 
}

Strangely this results in an Insert behaviour: an additional m_AttentionFlag with the same field values is added to the database with an associated m_PermissionCollection; the original remains intact without its m_PermissionCollections field being affected. Interestingly if you remove the lines marked ** and replace with an update to a simple public property on m_AttentionFlag e.g. flag.Description = "new description", the update proceeds as expected.

The DomainService methods are the default ones generated by the wizards, and the only point of interest is that changing the m_PermissionCollections field on the m_AttentionFlag changes the EntityState on the item to Added when it is sent to the server.

I've asked this question on the RIA services forum and a member suggested I look for multiple DomainContext instances, but the _context member is only created once, and the code listed here is pretty much the only code not generated by the various visual studio tools. Any ideas as to what's happening here?

Help much appreciated.

Steve

A: 

It turns out the problem lay in the default DomainService implementation provided by VS2010 and the RIA services preview.

The problem is detailed here:

http://www.riaservicesblog.net/Blog/post/Bug-in-the-Create-DomainService-wizard.aspx

Stephen Ellis