开发者

Nhibernate: On insert new record updating all existing records in table

I'm having a problem with NHibernate. I found this issue 开发者_StackOverflow中文版in NHibernate Profiler. When I try to insert a new record in the table It's triggering update statement for each record in table. Like if I have 1000 record in database on insert or update its triggering update statement for each record in database.

Here is my sample Here is my hbm file and sample code

<property name="ParentCodeId" column="Parent_Code_ID" not-null="false" />
<property name="Code" column="Diagnostic_Code" not-null="false" />
<property name="Descr" column="Description" not-null="true" />
<property name="Level" column="Level" not-null="true" />
<property name="CreatedBy" column="Created_By" not-null="true" />
<property name="CreatedDate" column="Created_Date" not-null="true" />
<property name="ModifiedBy" column="Modified_By" not-null="false" />
<property name="ModifiedDate" column="Modified_Date" not-null="false" />
<property name="IsActive" column="Is_Active" not-null="true" />

var repository = this.DomainObjectRepositoryFactory.Create<DiagnosticCodeRepository, DiagnosticCode>();
repository.BeginTransaction();
diagnosticCode.Id = data.DiagnosticCodeId;
diagnosticCode.ParentCodeId = data.ParentCodeId;
diagnosticCode.Code = data.Code;
diagnosticCode.Descr = data.Descr;
diagnosticCode.IsActive = data.IsActive;
diagnosticCode.Level = data.Level;

// save Diagnostic code
id = repository.Save(diagnosticCode);
repository.Commit();

Any Idea?

Thanks Imran


Is diagnosticCode a new object?

I don't know if this is your problem, but you might have better luck if you pull the object out of the database, make changes, then save it. You shouldn't ever have to set the id property on your objects by hand.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜