在实体框架中将字符串转换为通用T并调用方法

时间:2014-12-03 11:35:49

标签: c# entity-framework generics

我有以下课程,

 public class DataManagementService<T> where T : class
    {

        public virtual List<string> getFields()
        {
            var colNames = typeof(T).GetProperties().Select(a => a.Name).ToList();
            return colNames;
        }
   }

上述类返回特定表的列名(例如EMP_TAB)

class DataAccesAPI
{
   public List<string> getFields(string tableName)
    {
        Type typeArgument = Type.GetType(tableName);
        Type genericClass = typeof(DataManagementService<>);
        Type constructedClass = genericClass.MakeGenericType(typeArgument);
        object created = Activator.CreateInstance(constructedClass);

        var activity = new DataManagementService<??????>();
        return activity.getFields();
    }
}

我已根据其他解决方案更新了代码,但我仍然无法将类型传递给调用其方法所需的DataanagementService?

0 个答案:

没有答案