IDENTITY_INSERT不适用于实体框架DBSet.Add方法 [英] IDENTITY_INSERT ON not being respected for Entity Framework DBSet.Add method
本文介绍了IDENTITY_INSERT不适用于实体框架DBSet.Add方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
context.Database.SqlCommand("SET IDENTITY_INSERT [Songs] ON;");
在我添加方法之前(从DbSet添加方法)。
just before I do the Add method (the Add method from DbSet).
我的数据仍然使用身份值而不是我提供的ID。
My data still is using the identity value instead of the ID that I'm supplying.
我只想暂时(对于数据迁移),然后它将来应该保持自动生成的身份。
I only want this temporarily (for data migration) and then it should remain auto generated identity in the future.
我在我的数据库中使用SQL CE 4。
I'm using SQL CE 4 for my database.
推荐答案
EF不能猜测你已经执行了一个IDENTITY_SET命令并相应地更改其内部逻辑。
EF can't guess that you've executed an IDENTITY_SET command and change its internal logic accordingly.
如果需要插入特定的Id值,那么也可以使用SqlCommand进行插入。
If you need to insert specific Id values, use SqlCommand for the inserts too.
这篇关于IDENTITY_INSERT不适用于实体框架DBSet.Add方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文