How to make entity framework (3.5) skip selection of identity value after insert?
I have an entity mapped to a database table with an auto generated identity column.
After creating new entity and callingSaveChanges()
EF performs an insert query which also retrieves the new identity value for the newly inserted record.
Sometimes I do not care what is the new value (for example, I insert a new log record and I don't really care about开发者_如何学Python the identity value that was added).
Is there any way to make EF not querying for this value?Thanks,
ItayEDMX file defines such autogenerated property with attribute StoreGeneratedPattern="Identity"
. You have to modify EDMX directly and remove this attribute from both SSDL (and CSDL part probably as well). Changing the value from designer will only modify CSDL part which is not responsible for SQL generation. The problem is that after each update from database your SSDL will again contain this attribute because identity is defined in databse.
Edit:
The previous suggestion was theory. Actually I think it will not work because when you do not define the column in EDMX as identity it will send its actual value to database. In database it will raise exception because you will try to insert value to identity column without setting indentity insert on.
精彩评论