Sunday, October 14, 2018

What is EntityEntry?

Did you know that when you add something to a DbContext the Add method is not a void method? Behold:

EntityEntry<Cat> fuzzy = dbContext.Cats.Add(new Cat()
{
   Name = "Fuzzy",
   NumberOfLives = 9
});

 
 

Page 186 of "ASP.NET Core 2 and Angular 5" by Valerio De Sanctis pointed this out to me. The example code then does nothing with the EntityEntry so I don't really know why I could care yet. Maybe I could do...

int id = fuzzy.Entity.Id;

 
 

...downstream of the add to fish back out the unique id that just got created for the record at the database.

No comments:

Post a Comment