Sql 指定要在linq查询中更新的属性
我希望能够在linq表达式中指定要填充/更新的属性。 以下列方式的事物:Sql 指定要在linq查询中更新的属性,sql,linq,Sql,Linq,我希望能够在linq表达式中指定要填充/更新的属性。 以下列方式的事物: Proxy.UpdateEmployee(List<string> propertiesNames) Proxy.GetEmployee() //inside the method populate only certain properties Proxy.UpdateEmployee(列出属性名称) Proxy.GetEmployee()//在方法中仅填充某些属性 返回值必须是已知类型(不接受匿名类型)
Proxy.UpdateEmployee(List<string> propertiesNames)
Proxy.GetEmployee() //inside the method populate only certain properties
Proxy.UpdateEmployee(列出属性名称)
Proxy.GetEmployee()//在方法中仅填充某些属性
返回值必须是已知类型(不接受匿名类型)。
DLINQ允许通过指定属性的名称进行选择,但结果是
IQueryable
接口,我无法AsEnumerable
()它以便以后构建已知类型查询。必须使用反射按名称修改实例属性。
因此,无论何时使用LINQ更新对象,都需要执行以下操作:
foreach (string propName in propertiesNames)
{
PropertyInfo prop = this.GetType().GetProperty(propName);
prop.SetValue(valueForProp);
}
谢谢你的建议。尝试过这种方法后,速度会变慢并产生不必要的副作用……什么意思是产生不必要的副作用?比什么慢?给定要修改的属性的字符串名称,这是修改对象的唯一方法。