1
我想QueryOver並選擇返回私人財產的屬性。我無法解釋清楚,但這個例子會告訴你。NHibernate的QueryOver無法解析財產
映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="IWA.Model" assembly="IWA.Model">
<class name="Test" lazy="false" table="Test">
<id name="Id" column="Id" >
<generator class="identity" />
</id>
<bag name="_images" access="field" table="Image" cascade="none">
<key column="IdTest" />
<one-to-many class="Image" />
</bag>
</class>
</hibernate-mapping>
類:
public class Test : IEntity<int>
{
private readonly IList<Image> _images;
public Test()
{
_images = new List<Image>();
}
public int Id { get; set; }
public Image Image => _images.FirstOrDefault();
}
QueryOver:
TestDto r = null;
Session.QueryOver<Test>()
.Where(x => x.Id == _id)
.Select(
Projections.Property<Test>(x => x.Id).WithAlias(() => r.Id),
Projections.Property<Test>(x => x.Image).WithAlias(() => r.Image)
) .TransformUsing(Transformers.AliasToBean<TestDto>())
.SingleOrDefault<TestDto>();
當我嘗試此查詢時得到「有限沒有解決財產'。查詢沒有投影工作正常。
任何想法,我做錯了什麼?
你試過'Projections.SqlProjection'? – Najera
@Najera不,我從來沒有聽說過它。 –