Page 1 of 1

Sequence numbers + Entity key

Posted: Mon 08 Dec 2008 11:57
by Co
Last week i ran into a problem that serverside generation of pk-values(id) was not synchronized okay with the client after adding the items..A save of a parent with childs generated a lot of (parent key not found). What i did to resolve this is generate the id's myself in the partial class. (and remove the before insert triggers on the db)

However some values might change because of triggers...what i would do at present time is detach the item and requery it.

My question : is there a way to auto-requery an object?

Posted: Tue 09 Dec 2008 12:59
by AndreyR
Please describe the situation with client values synchronization more clearly.

Posted: Tue 09 Dec 2008 13:45
by Co
Okay some more info. I have an EntityObject with a Primary key PARENT_ID and a bunch of related childs (that object wise refer to the parent). When i perform a add of the parent all the childs fail because the generated parent-id(with a before insert trigger) differs from the expected one)

It looks that the values in the Primary key need to be filled in the Model instead of in the database. Is this assumption correct? (this is how i dow it now- removed the triggers and implemented the logic myself)

Posted: Fri 12 Dec 2008 14:30
by AndreyR
There is a way to use the DB triggers for auto-generating IDs.
Create trigger for inserting primary key values for master table.
In the generated .edmx file manually set StoreGeneratedPattern property value to "Identity" like following: The code like in the following example creates one master entity and two detail entities with autoinc_id field set to id of the master.id value.

Code: Select all

using (Entities db = new Entities()) {
        AUTOINC autoinc = new AUTOINC
        {
          FIELD = "test",
          AUTOINC_DETAILS = new System.Data.Objects.DataClasses.EntityCollection
          {
            new AUTOINC_DETAILS{
              DESCRIPTION = "Hello"
            },
            new AUTOINC_DETAILS{
              DESCRIPTION = "Hello again"
            }
          }
        };

Posted: Mon 15 Dec 2008 08:10
by Co
Thanx for the info :D this will increase the performance of my code a lot