简体   繁体   中英

Entity Framework SaveChanges doesn't work

I'm trying to save some records into a SQL Server database using EF6 and this code:

_db.MyEntity.Add(item);
_db.SaveChanges();

I can see the code/stored procedure in SQL Server Profiler (RPC:Completed) so it's being executed and when I run the same SQL manually in Management Studio, then the insert works OK (item has been inserted without errors).

在此处输入图像描述

Is there a reason why this doesn't work?

Am I missing something ( DbContext is OK as I have _db.Remove(item) few lines above that works fine)?

Ok, so the issue was caused by data type. SQL identity column was INT and in API model it was LONG. As I said, I wasn't getting any errors on executions and the sql code copied from sql server profiler worked when executed.

Changing LONG to INT32 in API model resolved this issue for me (insert from API works).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM