Sequence numbers + Entity key

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Co
Posts: 15
Joined: Fri 28 Nov 2008 10:59

Sequence numbers + Entity key

Post by Co » Mon 08 Dec 2008 11:57

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?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 09 Dec 2008 12:59

Please describe the situation with client values synchronization more clearly.

Co
Posts: 15
Joined: Fri 28 Nov 2008 10:59

Post by Co » Tue 09 Dec 2008 13:45

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)

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 12 Dec 2008 14:30

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"
            }
          }
        };

Co
Posts: 15
Joined: Fri 28 Nov 2008 10:59

Post by Co » Mon 15 Dec 2008 08:10

Thanx for the info :D this will increase the performance of my code a lot

Post Reply