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?
Sequence numbers + Entity key
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)
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)
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.
Create trigger for inserting primary key values for master table.
In the generated .edmx file manually set StoreGeneratedPattern property value to "Identity" like following:
Code: Select all
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"
}
}
};