Any*_*are 2 c# collections entity-framework list entity-framework-plus
如果我有一组像这样的实体(类):
Employee, Department, Room ... etc
Run Code Online (Sandbox Code Playgroud)
如何将这些类添加到列表而不是对象列表:
像这样 :
{Employee, Department, Room}
Run Code Online (Sandbox Code Playgroud)
我想得到这些类,因为我有一个带有以下签名的方法:
AuditManager.DefaultConfiguration.Exclude<T>();
Run Code Online (Sandbox Code Playgroud)
那么如何循环一个类列表并将它们传递给这个方法,例如:
AuditManager.DefaultConfiguration.Exclude<Employee>();
Run Code Online (Sandbox Code Playgroud)
小智 11
简单:
List<Type> types = new List<Type> {typeof(Employee), typeof(Department), typeof(Room)};
Run Code Online (Sandbox Code Playgroud)
或者您可以从现有对象获取类型:
List<Type> types = new List<Type> {EmployeeInstance.GetType(), DepartmentInstance.GetType(), RoomInstance.GetType()};
Run Code Online (Sandbox Code Playgroud)
我将尝试解释之间的差异Employee,typeof(Employee)但更好的将阅读此链接:
员工就像你的数据合同.它有X和Y等字段.
typeof(Employee)是您的"合同"类型,它包含有关字段的信息 - 包含有关X和Y字段的描述的信息.