如果没有首先将所有物体射入记忆,我怎么能够删除原封不动的物品?
这是可能的吗,还是我必须使用原始SQL?
如果没有首先将所有物体射入记忆,我怎么能够删除原封不动的物品?
这是可能的吗,还是我必须使用原始SQL?
使用ExecuteUpdate方法。下面的代码将以批处理方式提交批量删除。这适用于NHibernate 2.1.0。(不确定之前的版本)
foreach (List<int> batch in GetBatches(records, _batchSize))
{
using (ITransaction transaction = _session.BeginTransaction())
{
_session.CreateQuery(String.Format("DELETE FROM {0} WHERE Id IN (:idsList)", _domainObject.Name))
.SetParameterList("idsList", batch.ToArray())
.ExecuteUpdate();
transaction.Commit();
}
}
从NHibernate 5开始,你可以使用下列合成物:
session.Query<Cat>()
.Where(c => c.BodyWeight > 20)
.Delete();
从NHibernate开始 5.0, Linq查询可用于插入、更新或删除实体。 问询界定了删除、更新或插入数据,然后删除、更新、更新、更新、加入和插入可质疑的推广方法,以便删除该数据,或指示以何种方式加以更新或插入。 这些询问完全在数据库内进行,没有从数据库中提取相应的实体。
来源:http://nhibernate.info/doc/nhibernate-reference/querylinq.html#querylinq-modifying
Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...
Given the following Fluent NHibernate maps: public class FastTrackPackageClassMap : ClassMap<FastTrackPackage> { public FastTrackPackageClassMap() { Id(x => x.Id); ...
I had a scenario in Oracle where i need to match a substring part of column with a list of values. i was using sqlfunction projection for applying the substring on the required column, and added that ...
I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...
I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...
I have two associated business objects - A and B. the association is (A->B)many-to-one, with B.Id a foreign key in A (so A has A.B_id in the DB). I m using lazy=true and solved most of my problems, ...
Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...
I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....