1

I'm using dot net core 2.0, I have 2 classes, with a many to many relation defined.

Each class has a corresponding definition like so:

public virtual ICollection<INSERT_CLASS_HERE> MyObjects { get; set; }

I'm finding that I can retrieve a particular object for name or Id from the DB Context, yet the Collection that makes the many relationship, is coming up null.

I feel like it's something simple, but its been some time since I last touched dotnet... let alone dotnet core.

David van Dugteren
  • 3,879
  • 9
  • 33
  • 48
  • If you have in mind **EF Core**, see https://stackoverflow.com/questions/41881169/navigation-property-should-be-virtual-not-required-in-ef-core/41881299#41881299 – Ivan Stoev Sep 28 '17 at 08:36
  • @IvanStoev Interesting, although I'm struggling to find documentation on my question, it sounds like a collection of related objects must be queried at run time based on the foreign-key which would have to be manually set... which seems odd. I'm going to take another look at this tomorrow when my head is clear and ready for more dot net core anomolies and roadblocks :) – David van Dugteren Sep 28 '17 at 08:52
  • That's lazy loading. You need an `Include()` clause. Otherwise, remove the `virtual`. https://learn.microsoft.com/en-us/ef/core/querying/related-data – Steve Greene Sep 28 '17 at 14:15
  • @SteveGreene Thanks, I haven't touched dot net for some time, but decided to pick up dot net core for a project I'm working on... do you know if this is a Dot Net Core only kind of semantic? – David van Dugteren Sep 29 '17 at 00:47
  • It's an entity framework semantic. You can run EF 6 or EF Core with Dot Net Core. – Steve Greene Sep 29 '17 at 01:12

0 Answers0