Skip to main content

Microsoft Silverlight

Answered Question Hello, would like to know if this is guaranteed behavior in RIA...RSS Feed

(0)

tkousek
tkousek

Member

Member

15 points

40 Posts

Hello, would like to know if this is guaranteed behavior in RIA...

Hello

Thanks for the help on the previous question I had about my issue with the multiple contexts.  

 I have been referring to the riaservices preview document for the last month and am making really good progress in the application utilizing custom validation, etc...  

One thing that I have not been able to completely pinpoint down in the manual (maybe it's there but I might have missed it) is whether or not ria guarantees the following:

- I'm using the entity framework and Linqtoentitiesdomain service.   I have been able to update my .edmx from the database and it pulls in all of the enties.  In the DB, I declare my foreign keys so the associations are automatically generated.

My question is this:

Suppose I have a table called:

Company (with autoincrement called CompanyID as primary key)

and then another table called

Employee (with autoincrement as primary key called EmployeeID and a field called CompanyID which is a foreign key back to company)

and then another table called

EmployeePhones (with autoincrement as primary key and foreign key field called EmployeeID back to employee)

In RIA, if I add a "brand" new Company entity to the context (Company id is 0 because it has not been saved to the DB yet) and then add a brand new Employee entity to the Company (Employee id is 0 because it has not been saved to the DB yet) and then 2 brand new EmployeePhones to the 1 new Employee entity,

Will I be guaranteed that at submitchange time, RIA will see that these are "new" and it will call in this order:

- InsertCompany (for the new company entity and will pick up the newly created CompanyID autoincrement for the next step)

- InsertEmployee (for the new employee entity in the company and will use the newly created CompanyID in it's parent and will generate a new value for EmployeeID)

- InsertEmployeePhone   2 times for the new phone entity within employee and will use the newly created EmployeeID (generated in previous step) for it's parent

===============

I'm doing such a thing right now and have noticed this behavior and I'm not having to fill in the foreign key values in teh child tables as they're automatically being propogated down.

I love this feature of RIA but can I rely on that behavior all the time or should I not rely on that.   I'm not seeing in the manual where it states that the foreign keys back to the parent will be automatically at the time the children are added.

This is only in the case where ALL of the records are new and have not been persisted to the DB.  When the parent's have not been yet persisted, the value in their primary autogenerated key field is 0 (or I can change to -1?)

In the other case where I add children to already existing (in the DB) entities, I simply add the child row in the parent's entity collection and it works great. 

thanks!!!

ColinBlair
ColinBlair

Contributor

Contributor

6305 points

1,236 Posts

Answered Question

Re: Hello, would like to know if this is guaranteed behavior in RIA...

Yes,that should all be guaranteed as long as the model as all of the associations setup correctly. It is important to understand though that none of this is a function of RIA Services, which is why you can't find anything about it in the documentation. All of that is being done by Entity Framework (or NHibernate or L2S). The one thing that RIA Services does is check to see if the entities were changed during the save and send those changes back to the client so that the client knows what the keys are.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

tkousek
tkousek

Member

Member

15 points

40 Posts

Re: Re: Hello, would like to know if this is guaranteed behavior in RIA...

aha!!!   Makes sense now!!!

 thanks a million for all your help!!!

On a side note, one thing I have noticed with VS2008 and the entity framework thru the designer is that when I add a new column to a table or a new foreign key, the designer from studio does not always import it when I choose "Update Model from Database" thru the designer.   In some cases, I literally have to delete the entity (and all of it's related entities and associations) from the designer *and* I have to manually go into the .edmx (thru notepad++) and physically find and delete all of the related entities and keys.   Then when I do "Update model from database", it works.   This happens to me a lot which is why it's somewhat painful when I add new columns and/or keys to my table.   I suspect this is a problem with the VS2008 designer.  I'm using mysql.   Anyhow, it involves alot of manually going into the .edmx and physically deleting xml blocks...  

Don't know if you or others have had the same problem?   Hopefully, it's fixed in VS2010.

thanks again for all your help.

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities