2
我有實體:延遲加載返回相等的記錄
public class Document : PersistentObjectBase
{
public virtual long? FolderId
{
get;
set;
}
}
<id name="Id" column="ID">
<generator class="identity" />
</id>
<version column="VERSION" name="Version" type="Int64" unsaved-value="undefined" />
<property name="FolderId" column="FOLDER" />
public class DocumentFolder : PersistentObjectBase
{
public virtual long? ParentFolderId
{
get;
set;
}
#region [Lazy subfolders]
protected virtual IList<DocumentFolder> NSubFolders
{
get;
set;
}
public virtual IList<DocumentFolder> SubFolders
{
get
{
return GetObjectWithInitializationCheck(NSubFolders);
}
set
{
NSubFolders = value;
}
}
#endregion
#region [Lazy Documents]
protected virtual IList<Document> NDocuments
{
get;
set;
}
public virtual IList<Document> Documents
{
get
{
return GetObjectWithInitializationCheck(NDocuments);
}
set
{
NDocuments = value;
}
}
#endregion
}
其中:
protected static T GetObjectWithInitializationCheck<T>(T propertyValue) where T : class
{
if (ObjectInitialized(propertyValue))
{
return propertyValue;
}
return null;
}
<id name="Id" column="ID">
<generator class="identity" />
</id>
<version column="VERSION" name="Version" type="Int64" unsaved-value="undefined" />
<property name="ParentFolderId" column="PARENT_FOLDER_ID" />
<bag name="NSubFolders" lazy="true" cascade="delete">
<key column="PARENT_FOLDER_ID" />
<one-to-many class="DocumentFolder" />
</bag>
<bag name="NDocuments" lazy="true">
<key column="FOLDER" />
<one-to-many class="Document" />
</bag>
在建設標準,我做的:
criteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
criteria.CreateCriteria("NSubFolders", "subFolders", JoinType.LeftOuterJoin);
criteria.CreateCriteria("NDocuments", "documents", JoinType.LeftOuterJoin);
該方法返回子文件夾和文件夾,但它是有可能找到在列表中多次的文件夾或文件。 例如,我只有30個文件夾,但我得到的文件夾大於1次的文件夾大約有180個。 對不起,我的英語差......
例如.... – 2010-10-29 15:06:19
只要使用選擇,不要使用任何種類的連接 – Falcon 2010-10-29 15:12:32