Last post Feb 21, 2021 06:09 PM by Basquiat
Feb 21, 2021 12:09 PM|Basquiat|LINK
Using EF Core 5.0.3
From EF 5, many-to-many relationships are supported.
The following worked under EF 5.0.2 but returns "Object not reference not set to an instance of the Object" with EF 5.0.3
var p = new Post()
Name = "new Post"
var t = new Tag()
Name = "some Tag"
I noticed that in the Join table; EF 5.0.3 have the Foreign Keys as FK_PostTag_Posts_PostsId and FK_PostTag_Tags_TagsId
But EF 5.0.2 had it singuar as FK_PostTag_Posts_PostId and FK_PostTag_Tags_TagId
Anyone know whether something changed, or how to now add an item to the many-to-many relationship?
Feb 21, 2021 06:09 PM|Basquiat|LINK
Ok, it works if you specifically use the Include function.
var post = _db.Posts.Include(t => t.Tags).FirstOrDefault(p =>p.Id == postToEdit.Id);