Reputation: 1269
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 when 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!
Upvotes: 1
Views: 868