开发者

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 calling SaveChanges() 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,

Itay


EDMX 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜