1
매핑 된 nhibernate 클래스를 쿼리하려고하지만 결과가 매핑되지 않은 객체 여야합니다. 매핑 및 매핑되지 않은 클래스는 다음과 같습니다 :Criteria-api를 사용하여 매핑되지 않은 객체를 반환하는 NHibernate 쿼리
[Class(NameType = typeof(ClassA)]
public class ClassA
{
[Cache(0, Usage = CacheUsage.ReadWrite)]
[Id(1, Name = "Id", UnsavedValue = null)]
[Generator(2, Class = "native")]
public virtual long? Id { get; set; }
[Property]
public virtual string PropertyA { get; set; }
[Property]
public virtual string PropertyB { get; set; }
}
public class ClassB
{
public string PropertyA { get; set; }
public string PropertyB { get; set; }
public int Number { get; set; }
}
그리고 내가 원하는 결과를 얻기 위해이 방법을 사용 : 이것은 잘 작동하지만 할 수있는보다 직접적인 방법이없는
public ICollection<ClassB> Group()
{
var result =
Session.CreateCriteria(typeof(ClassA)).SetProjection(
Projections.ProjectionList().Add(Projections.RowCount(), "Number")
.Add(Projections.GroupProperty("PropertyA"))
.Add(Projections.GroupProperty("PropertyB")));
return
(result.List().Cast<IList>().Select(
entry =>
new ClassB {
Number = (int)entry[0],
PropertyA = (string)entry[1],
PropertyB = (string)entry[2]
}
)).ToList();
}
이 기준을 사용하여 - API를?
감사, 재산 예측을 포장해야합니다 않습니다. 나는 프로젝션에 explixit 별칭을 주어서 다음과 같이 작동하도록했다 :'.Add (Projections.GroupProperty ("PropertyA"), "PropertyA")' –
@Rian, 아, 네, 잊어 버렸습니다. 내 대답을 편집합니다. – Vadim