开发者

SaveChanges() doesn't work?

I have the following code:

User user = new User();

user.Name = "ABC";
user.Age = "12";

_context.AddToUser(user);
_context.SaveChanges();

Meta meta = new Meta();

meta.UserID = user.ID;
meta.Info = "User Info";

_context.AddToMeta(meta);
_context.SaveChanges();

User.ID is Identity and is set to increase by 1 wh开发者_高级运维en a new record was inserted. When I run the above code. I got a new user ID by using user.ID but there is no new record was added in User table.

If I comment the last _context.SaveChanges() then the new record is added. I'm new with EF, I've searched for a while but still don't know why.

Any helps would be appreciated!


you forgot:

_context.AddToMeta(meta);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜