lundi 17 juillet 2017

Get entities by string in Entity Framework

I am trying to do some dynamic code using Entity Framework. I have a model (Model1) with one table(Test1), it's simple. What I'm trying to do is accessing the model Test1 programatically with the name of the table, to use it after in differents tasks. I was looking for in google and I have found Finding entities by key in entity framework but it's doesnt work, or I don't have any idea...

When I ran this code it breaks on trying to set entityProperty

Model1Container m = new Model1Container();
            PropertyInfo entityProperty = m.GetType().GetProperties().Where(t => t.Name == "Test1").Single();
            var baseQuery = (IQueryable<IIdentity>)entityProperty.GetValue(m, null);

Sorry for the explanation.

Any ideas?





Aucun commentaire:

Enregistrer un commentaire