Skip to main content

Microsoft Silverlight

Answered Question Can update entity, but can't insert a new entityRSS Feed

(0)

David Duey
David Duey

Member

Member

1 points

4 Posts

Can update entity, but can't insert a new entity

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
jps777

Member

Member

6 points

14 Posts

Re: Can update entity, but can't insert a new entity

 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
VijayUpadya

Member

Member

182 points

41 Posts

Re: Can update entity, but can't insert a new entity

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

Thanks,
Vijay [MSFT]

David Duey
David Duey

Member

Member

1 points

4 Posts

Re: Can update entity, but can't insert a new entity

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.

David Duey
David Duey

Member

Member

1 points

4 Posts

Re: Can update entity, but can't insert a new entity

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
Nedster657

Member

Member

48 points

63 Posts

Answered Question

Re: Can update entity, but can't insert a new entity

I had this when I was passing null values in the Entity string properties. I changed to an empty string and the insert worked.

David Duey
David Duey

Member

Member

1 points

4 Posts

Re: Can update entity, but can't insert a new entity

@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
glasin

Member

Member

9 points

8 Posts

Re: Can update entity, but can't insert a new entity

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.

glasin
glasin

Member

Member

9 points

8 Posts

Re: Can update entity, but can't insert a new entity

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities