Hello! 

Is it possible to force NHibernate to fetch a property value using CASE 
WHEN sql-sytax, when this property is defined in a few subclasses?


Domain model:


[TableName("clazz_A")] 
public class ClazzA : Entity 
{ public virtual String Name { get; set; } } 

[TableName("clazz_A1")] 
public class ClazzA1 : ClazzA 
{ public virtual String Number { get; set; } } 

[TableName("clazz_A2")] 
public class ClazzA2 : ClazzA 
{ public virtual String Number { get; set; } } 

[TableName("clazz_B")] 
public class ClazzB : Entity 
{ public virtual ClazzA A { get; set; } }

NHibernate request:


ICriteria criteria = Unity.Resolve<ISession>().CreateCriteria("ClazzB"); 
criteria = criteria.CreateAlias("A", "_A", JoinType.LeftOuterJoin); 
var projectionList = Projections.ProjectionList(); 
projectionList.Add(Projections.Property("_A.Number")); 
criteria.SetProjection(projectionList); 
IEnumerable<object> futureResults = criteria.Future<object>(); 
var records = futureResults.ToList();

SQL: 


SELECT a1_1_.Number as y0_ 
FROM clazz_B this_ 
left outer join clazz_A a1_ on this_.AId=a1_.Id
left outer join clazz_A1 a1_1_ on a1_.Id=a1_1_.Id 
left outer join clazz_A2 a1_2_ on a1_.Id=a1_2_.Id;

NHibernate fetches 'Number' property only from the first sub-table, but I 
need something like this


CASE 
WHEN a1_1_.Id IS NOT NULL THEN a1_1_.Number 
WHEN a1_2_.Id IS NOT NULL THEN a1_2_.Number 
END as y0_

Is there any way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to