Reputation: 399
My dbContext
always returns null for my junction table. Can I solve the problem by not changing the DB relationship design?
My problem
I want just Id = 1
and Stationery_Id = 1
and UOM_Id = 1
Here is all the detail information...
Database Design
Class
Data in my db
Upvotes: 0
Views: 259
Reputation: 1673
I think it's related to lazy loading
. As this tutorial said:
Lazy loading is
delaying
the loading of related data until you specifically request for it
You never ever request related data directly in this code snippet, so the expectation of loading related data is wrong.
If you wanna load related data at the moment, you can use Include
to achieve that:
db.StockUOMs.Include(i => i.UOM).Include(i => i.Stationery).ToList();
for a deep dive, you can follow this link.
good luck.
Upvotes: 1