更新:我尝试过的事情 - 请参阅下面的答案以获得解决方案
我们有一个看起来像一个应用程序的webforms和MVC3应用程序.这部署在许多环境(2003,2008,Win 7)中并且正常运行.我刚刚在新的Windows Server 2012计算机上设置了这些应用程序,除了获取MVC站点的资源文件外,一切正常.浏览器获得了
500 Internal Server Error
Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable. Please hit the "Refresh" button in your web browser to retry your request.
Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this …Run Code Online (Sandbox Code Playgroud) 我分别获取一个对象列表(而不是来自 NHibernate)并将父对象 IEnumerable 设置为等于这个返回的对象。最初,我们只需要读取对象。然后我们只需要更新父级上的特定字段。最近,我们需要更新孩子的字段。到目前为止,SaveOrUpdate() 一切正常。现在,即使孩子的集合附加到分离的父对象(不使用 NHibernate),我也需要更新孩子。以下代码导致更新父级,但不更新子级。如果我都做了,那么如果父级没有集合,子级将被删除。我不想这样做,因为我担心无法解释这种行为的遗留用途。
期望的行为:
1. 级联对集合的任何更改(无论父项中是否由 NHibernate 检索)。2. 即使父级没有子级集合,也不要删除对象。
这可能吗?
这是我们的 NHibernate 保存方法:
[Transaction]
public int? Save(DocumentFieldDTO entity, bool autoFlush)
{
var persisted = CurrentSession.Merge(entity);
entity.DocumentFieldID = persisted.DocumentFieldID;
if (autoFlush) { CurrentSession.Flush(); }
return entity.DocumentFieldID;
}
Run Code Online (Sandbox Code Playgroud)
DocumentFieldDTOMap 看起来像这样:
public class DocumentFieldDTOMap : EntityMapBase
{
public DocumentFieldDTOMap()
{
Table("DocumentField");
Id(m => m.DocumentFieldID).GeneratedBy.Increment().UnsavedValue(null);
Map(x => x.Name);
Map(x => x.DocumentSectionID).Not.Update();
// .... Lots of other fields ....//
HasMany(x => x.DocumentFieldOrgs)
.Cascade.SaveUpdate()
.LazyLoad()
.KeyColumn("DocumentFieldID");
}
}
Run Code Online (Sandbox Code Playgroud)
}
如果我更改Cascade.SaveUpdate()为Cascade.All() …
更新:我会尽快得到查询计划.
我们的查询效果不佳,需要4分钟才能完成特定组织.在通常的重新编译之后,存储的proc和更新统计信息没有帮助,我们将if Exists(...)重写为select count(*)...以及4分钟到70毫秒的存储过程.条件使得70毫秒查询需要4分钟的问题是什么?查看示例
这些都需要4分钟以上:
if (
SELECT COUNT(*)
FROM ObservationOrganism omo
JOIN Observation om ON om.ObservationID = omo.ObservationMicID
JOIN Organism o ON o.OrganismID = omo.OrganismID
JOIN ObservationMicDrug omd ON omd.ObservationOrganismID = omo.ObservationOrganismID
JOIN SIRN srn ON srn.SIRNID = omd.SIRNID
JOIN OrganismDrug od ON od.OrganismDrugID = omd.OrganismDrugID
WHERE
om.StatusCode IN ('F', 'C')
AND o.OrganismGroupID <> -1
AND od.OrganismDrugGroupID <> -1
AND (om.LabType <> 'screen' OR om.LabType IS NULL)) > 0
print 'records';
Run Code Online (Sandbox Code Playgroud)
-
IF (EXISTS(
SELECT *
FROM ObservationOrganism omo …Run Code Online (Sandbox Code Playgroud)