as stated in the title i'm using Entity Framework 4.1 to connect to a SA 12 database. Some of the entities in my EDM have properties where the values are generated by the database (using insert/update triggers). EF supports that by setting the StoreGeneratedPattern attribute to the corresponding properties of the entities. There are 2 values (beside None = no database generated values): Identity (which means the value is generated after an insert) and Computed (which means the value is generated after inserts and updates). I use both kinds.
I set these attributes a while ago without (unfortunately) thoroughly testing if it worked correctly, because by the first look it seemed to work perfectly.
But now on a second look i see that newly inserted entities do not display the correct values immediately after the SaveChanges call on the DbContext. After reloading the entity the correct database generated values are displayed (which means the actual trigger logic works).
I use the Entity Profiler to analyze the queries/commands the EF generates, and took a closer look at the insert statement. After the actual insert statement there is a select statement which tries to get the database generated values for the corresponding columns, that looks like the following:
select [SOME_GENERATED_NO], -- StoreGeneratedPattern: Identity [CREATED_AT], -- StoreGeneratedPattern: Identity [CREATED_BY], -- StoreGeneratedPattern: Identity [CHANGED_AT], -- StoreGeneratedPattern: Computed [CHANGED_BY] -- StoreGeneratedPattern: Computed from [MY_TABLE] where @@ROWCOUNT > 0
The problem here is, that there is no filter for the new ID (primary key) of the inserted row (the ID is set by my allication before saving). So the result set contains all rows of MY_TABLE that exists (although Entity Profiler reports a row count of only 1). But i always get the store-generated values of the first row of MY_TABLE (which of course is not the newly inserted).
Is this a known problem with the current version of the SA Data Provider for EF or could i have overlooked some other detail (maybe a configuration in the EDM)?
Another problem that i encountered is that for some other entities that have store-generated value columns there is no select statement to retrieve generated values after inserts/updates at all.
Thanks for any help on this topic.
Thanks for pointing out the problem. The bug is fixed in 188.8.131.5219 (or any later update) which may become available soon. EBF number is 704978.
answered 13 Apr '12, 14:40
(Note: Thas was converted from a question comment...)
Then I don't have a clue. Are you testing with the newest 12.0.1 EBF?
EDIT: As you are not, it seems worth trying a new one...and see if that has an effect...