Skip to main content
Home Forums Silverlight Programming WCF RIA Services Can update entity, but can't insert a new entity
8 replies. Latest Post by glasin on July 7, 2009.
(0)
David Duey
Member
1 points
4 Posts
04-29-2009 3:24 PM |
I'm using RIA Services in Silverlight with a DataForm control; I can update existing entities and the updates persist in the database, but I can't get a new entity to persist in the database. When I update an entity and call myContext.SubmitChanges, the UpdateEntity function is called on the sever side; however, when I add a new entity, the InsertEntity function is not called on the server side. I've stepped throught the code, but I haven't found how the new entity is propogated down to the server. I don't receive any errors.
Any suggestions?
Thanks!
jps777
6 points
14 Posts
04-29-2009 8:48 PM |
Check out this post to see if anything there is helpful. Also, I've found sections 3 and 5 of the riaserviceoverview document found here useful.
VijayUpadya
182 points
41 Posts
04-30-2009 12:54 AM |
Have you checked whether insert indeed is happening on the client? You can check it by inspecting added entities collection via
domainContext.Entities.GetChanges().AddedEntities
04-30-2009 10:23 AM |
Yes, the new entity is inserted on the client side.
To give you a little more information, the table where the entity's data is persisted uses a auto-generated (identity) field for the key value. All other values can be null.
04-30-2009 10:29 AM |
Thanks for the links! The dataform is adding the new entity to the entities collection on the client; however the update function on the server isn't being called. I'll have study the RIA documentation to see if there's something I'm missing. Again, thanks for the links!
Nedster657
48 points
63 Posts
04-30-2009 11:46 AM |
I had this when I was passing null values in the Entity string properties. I changed to an empty string and the insert worked.
04-30-2009 1:57 PM |
@Nedster657 Thank you very much! Changing the null string values to empty strings did help. Now the insert function on the server side is firing. It still not saving the data, but it's a step in the right direction. Thanks again!
glasin
9 points
8 Posts
07-06-2009 11:28 PM |
Has you found out how to actually save the data into database? I have a similar problem. The server side insert method is called. But no new row in the database, no exception either.
Assessment is the entity. AssessmentOID is the PK.
public void InsertAssessment(Assessment assessment) { if (assessment.AssessmentOID.Equals(Guid.Empty)) assessment.AssessmentOID = Guid.NewGuid(); assessment.WhenCreated = DateTime.Today; this.Context.AddToAssessment(assessment); }
I have a feeling my problem is on how to commit the changes (ie. the insert) using the Context.
I called SubmitChanges() on the client side and that worked for update. but not for insert.
07-07-2009 3:15 AM |
In my case, the fail was due to a foreign key constraint in database. There could be many other reasons why it may fail, to see the error, you have to handle the SubmittedChanges event from the DomainDataSource. Inside the handler, try e.Error.Message to see the error message.