我有一个列名列表,我想动态更新表并将这些列的所有行设置为 NULL。当前代码正在使用if
逻辑,并且需要在列列表更改时不断更新
var columns = new string[] {"FirstName","LastName"};
using(var scope = new TransactionScope())
{
foreach(var col in columns)
{
if(col == "FirstName")
{
dbContext.Users
.Where(x=>x.ParentID = 1234)
.Update(x=> new User()
{
FirstName = null
}
}
if(col == "LastName")
{
dbContext.Users
.Where(x=>x.ParentID = 1234)
.Update(x=> new User()
{
LastName = null
}
}
}
scope.Complete();
}
我还在使用带有 EF 6 的动态 LINQ和Z 框架。有没有办法动态更新表的某些列? (我也可以构造 sql 更新字符串执行为 CommandText,但我试图避免这种情况)