(아래의 코드는 예제 일 뿐이므로 필요한 이유에 대해 언급하지 마십시오. 예 또는 아니오에 대한 명확한 답변을 주시면 감사하겠습니다. 질문은 나에게도 알려 모호 감사)T가 동적 인 런타임에 Entity-Framework에서 ObjectSet <T>을 얻으려면 어떻게해야합니까?
예, 나는 아래 ObjectSet < T> 얻을 수 있습니다.! 위의 코드는 괜찮 작동
ObjectSet<Users> userSet = dbContext.CreateObjectSet<Users>();
ObjectSet<Categories> categorySet = dbContext.CreateObjectSet<Categories>();
합니다. 그러나 엔터티 테이블이 동적이어야하므로 형식간에 전환 할 수 있습니다. 아래처럼.
//var type = typeof(Users);
var type = typeof(Categories);
Object<type> objectSet = dbContext.CreateObjectSet<type>();
위의 코드는 컴파일되지 않습니다.
[편집 :] :
//string tableName = "Users";
string tableName = "Categories";
ObjectSet objectSet = dbContext.GetObjectSetByTableName(tablename);
의 중복 가능성 (http://stackoverflow.com/questions/ 232535 / how-to-use-reflection-to-call-generic-method) – nawfal