How to call submit operation twice in one process in Silverlight?

130 views Asked by At

I am working with Silverlight application with MVVM Concept and Entity framework and having some trouble in inserting the values. Using SubmitChanges method to update, insert, or delete data.

All of the pending changes are submitted in one operation.

Is it possible to use SubmitChanges method twice in one process?

Because I have below requirement:

  1. In First step am inserting data into Table B.
  2. Second step am inserting data into Table A. Here Table A has FK relation to Table B. That's why I am inserting data(Table B) in first step only.

But problem is: submitChange method insert all pending changes at once.

I need to submit the data twice in one process.

1

There are 1 answers

0
Greg On

Entity Framework will handle the inserts correctly only if you setup the relationships correctly. You do not have to worry about the sequence of the inserts. Entity Framework will sort that out automatically. As a test, open a new diagram of your database and you should see a one to one or one to many relationship between TableA and TableB. If you do not see this relationship, EF will not know how to do the inserts.

Entity Framework will infer the sequence. If you check your object just before the context inserts the record, you should see zero's in the identity columns of both Parent and Child objects. EF will hydrate these properties with the identity values once the record(s) have been inserted.