2

I have a DbContext that looks like this:

 public partial class MyDbConnectionConnection : DbContext
    {
        public MyDbConnectionConnection()
            : base("name=MyDbConnectionConnection ")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<Name> tbName{ get; set; }
        public DbSet<Surname> tbSurname{ get; set; }
        public DbSet<Address> tbAddress{ get; set; }
        public DbSet<Currency> tbCurrency { get; set; }
  }
}

and I need to search through this Context and find data set that matches the table name for example:

   public dynamic getCorrectEntity()
    {
        MyDbConnectionConnection Context = new MyDbConnectionConnection();
        var dbset = Context.Set(Type.GetType("tbName"));

        return dbset;
    }

where "tbName" is name of DbSet.

I cannot get anything!

In this line of code Type.GetType("tbName") it returns value null.

I just need to mentioned that I googled, try all examples I found here in the last couple of hours but nothing helps :(

Does anyone know how to get entity on this way?

P.S. I also try all this using Assembly.GetType(name). It didn't help...

Yuniku_123
  • 269
  • 1
  • 5
  • 18

0 Answers0