在使用应用标准获取集合时,我遇到了一些问题。
public class Ship
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual IList<Structure> Structures { get; set; }
public Ship()
{
Structures = new List<Structure>();
}
public virtual void AddStructure(Structure structure)
{
Structures.Add(structure);
}
}
public class Structure
{
public virtual int StructureId { get; protected set; }
public virtual string Name { get; set; }
public virtual Ship Ship { get; set; }
public virtual int Score { get; set; }
public virtual IList<StructureGeometry> StructuresGeomtries { get; set; }
public Structure()
{
StructuresGeomtries = new List<StructureGeometry>();
}
}
public class StructureGeometry
{
public virtual int StructureGeomId { get; protected set; }
public virtual string Name { get; set; }
public virtual Structure Structure { get; set; }
public StructureGeometry()
{
}
}
public class StructureMap : ClassMap<Structure>
{
public StructureMap()
{
Id(x => x.StructureId).GeneratedBy.Increment();
Map(x => x.Name);
Map(x => x.Score);
References(x => x.Ship);
HasMany(x => x.StructuresGeomtries)
.Cascade.All()
.Inverse();
}
}
DetachedCriteria query = DetachedCriteria.For(typeof(Structure), "structure");
Disjunction juction = Restrictions.Disjunction();
juction.Add(NHibernate.Criterion.Expression.Like("Score", 1));
juction.Add(NHibernate.Criterion.Expression.Like("Score", 3));
query.Add(juction);
Disjunction structureGeometryjuction = Restrictions.Disjunction();
structureGeometryjuction.Add(NHibernate.Criterion.Expression.Like("Name", "SGeom3"));
DetachedCriteria structuGeomCriteria = DetachedCriteria.For(typeof(StructureGeometry));
structuGeomCriteria.Add(structureGeometryjuction);
structuGeomCriteria.SetProjection(Projections.ProjectionList().Add(Projections.Property("Name"), "StructGeomName"));
query.CreateCriteria("structure.StructuresGeomtries", "structureGeometry")
.Add(Subqueries.Exists(structuGeomCriteria));
var structures = query.GetExecutableCriteria(session).List<Structure>();
structures[0].StructuresGeomtries
根据关联获取。我没有创建任何 DTO,我正在从同一个实体(POCO)中获取数据。
我无法在集合属性上应用过滤器或标准。Nhibernate 默认情况下根据一对多关联选择所有几何图形。
因此,我能够根据标准获取我的根父级,但无法将标准应用于集合属性。
谢谢,