public List<string> GetColumnsForTable(string table)
{
var context = _unitOfWork.GetContext();
var names = typeof(table).GetProperties()
.Select(property => property.Name)
.ToArray();
return names ;
}
实体对象的需要类型,但我从下拉列表中选择了字符串
typeof(table).GetProperties()
在c#
中是否有其他方法可以从实体框架中获取列答案 0 :(得分:0)
一个例子。您可以使用反射来获得正确类型的对象
让我们说对象在namespace People.Family
和班级Dad
Type myType = Type.GetType("People.Family.Dad");
var names = myType.GetProperties().Select(pro => pro.Name).ToArray();
您仍然会面临必须指定所有对象命名空间和所有对象命名空间的问题。希望它能让你了解什么是可能的。