Jer*_*eme 3 linq nhibernate bulk
不确定我是否在这里遗漏了什么。基本上,我正在寻找 Linq to Nhibernate 来执行以下 SQL 语句:
update SomeTable
set SomeInteger = (SomeInteger + 1)
where SomeInteger > @NotSoMagicNumber
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?
谢谢!
迟到的答案,但它现在存在于 Nhibernate 5.0 中。
//
// Summary:
// Update all entities selected by the specified query. The update operation is
// performed in the database without reading the entities out of it.
//
// Parameters:
// source:
// The query matching the entities to update.
//
// expression:
// The update setters expressed as a member initialization of updated entities,
// e.g. x => new Dog { Name = x.Name, Age = x.Age + 5 }. Unset members are ignored
// and left untouched.
//
// Type parameters:
// TSource:
// The type of the elements of source.
//
// Returns:
// The number of updated entities.
public static int Update<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, TSource>> expression);
Run Code Online (Sandbox Code Playgroud)
在你的情况下:
session.Query<SomeObject>()
.Update(i => new SomeObject { SomeInteger = i.SomeInteger + 1 });
Run Code Online (Sandbox Code Playgroud)
感谢 NHibernate 团队!