How to use DbContext if there is no DbSet <> in it, for request?

I am using Entity Framework Code-First and this is my DbContext . As you can see, there is nothing about the properties of DbSet <> , and all this will provide my model classes, which are provided by C # CodeDOM . I am dynamically creating dynamic tables using Code-First .

  public class MyDBContext : DbContext { public MyDBContext() : base("MyCon") { Database.SetInitializer<MyDBContext>(new CreateDatabaseIfNotExists<MyDBContext>()); } protected override void OnModelCreating(DbModelBuilder modelBuilder) { var entityMethod = typeof(DbModelBuilder).GetMethod("Entity"); var theList = Assembly.GetExecutingAssembly().GetTypes() .Where(t => t.Namespace == "FullDynamicWepApp.Data.Domins") .ToList(); foreach (var item in theList) { entityMethod.MakeGenericMethod(item) .Invoke(modelBuilder, new object[] { }); } base.OnModelCreating(modelBuilder); } } 

but now I don’t know how to write my Linq query without a DbSet <> inside my DbContext ? make an instance of my dbcontext and use which property?

  MyDBContext Db = new MyDBContext(); Db.What??????? 

How can I write my CRUD s operation in these circumstances?

+1
source share
1 answer

The DbContext.Set<TEntity> method returns DbSet<TEntity> for this type, for example:

 Db.Set<Entity>().Add(entity); 
0
source

Source: https://habr.com/ru/post/1257587/


All Articles