I need to call 3 diferents views from my db context, but 3 views return sameview model.so how to declare 3 views and retund types in context class and onmodel builder creating.
public virtual DbSet
public virtual DbSet
public virtual DbSet
modelBuilder.Entity
modelBuilder.Entity
modelBuilder.Entity
Amit MohantyPosted Apr 24, 2023, 4:12 AM
You cannot use the same entity type (
VwM) to map to multiple views in the sameDbContext. However, you can create a separate class for each view, even though they have the same model.Tuhin PaulPosted Apr 23, 2023, 12:54 PM
Part 2
In your DbContext class, create a DbSet for each view and map it to the corresponding model class:
Now you can query each view using the corresponding DbSet:
Tuhin PaulPosted Apr 23, 2023, 12:53 PM
Part 1
Create separate model classes for each view:
Tuhin PaulPosted Apr 23, 2023, 12:52 PM
You cannot declare multiple DbSets with the same model type in your DbContext class as it will cause conflicts. Instead, you can create separate model classes for each view and map them accordingly in your DbContext's OnModelCreating method.