Triple K
Triple K

Reputation: 399

Asp.net MVC Many to Many Junction Table

My dbContext always returns null for my junction table. Can I solve the problem by not changing the DB relationship design?

My problem

enter image description here

I want just Id = 1 and Stationery_Id = 1 and UOM_Id = 1

Here is all the detail information...

Database Design

Database design

Class

enter image description here

Data in my db

enter image description here

Upvotes: 0

Views: 259

Answers (1)

Hamed Moghadasi
Hamed Moghadasi

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

Related Questions