gpt4 book ai didi

Linq 到 Nhibernate 批量更新查询等效?

转载 作者:行者123 更新时间:2023-12-01 10:14:48 26 4
gpt4 key购买 nike

不确定我是否遗漏了这里的任何内容。基本上,我正在寻找 Linq to Nhibernate 来执行以下 SQL 语句:

update SomeTable
set SomeInteger = (SomeInteger + 1)
where SomeInteger > @NotSoMagicNumber

有什么办法吗?

谢谢!

最佳答案

迟到的答案,但它现在存在于 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);

在你的情况下:

    session.Query<SomeObject>()
.Update(i => new SomeObject { SomeInteger = i.SomeInteger + 1 });

感谢 NHibernate 团队!

关于Linq 到 Nhibernate 批量更新查询等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2114191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com