Little more info to help figure out what is going on. When I use
QueryOver<>.Where(x => x.Shape is Cirlce) I get this error

Execute
        System.Exception: Could not determine member type from (x.Shape Is
Circle)
        at
NHibernate.Impl.ExpressionProcessor.ProcessBooleanExpression(Expression
expression)
        at NHibernate.Impl.ExpressionProcessor.ProcessExpression(Expression
expression)
        at
NHibernate.Impl.ExpressionProcessor.ProcessLambdaExpression(LambdaExpression
expression)
        at NHibernate.Impl.ExpressionProcessor.ProcessExpression[T]
(Expression`1 expression)
        at NHibernate.Criterion.QueryOver`2.Add(Expression`1 expression)
        at NHibernate.Criterion.QueryOver`2.Where(Expression`1 expression)
        at
NHibernate.Criterion.QueryOver`2.NHibernate.IQueryOver<TRoot,TSubType>.Where(Expression`1
expression)
        DogRepositoryTests.cs(32,0): at
NHibernateScratchpad.Tests.ToyBoxRepositoryTests.Test()

On Sep 10, 12:01 pm, MichaelK <[email protected]> wrote:
> The above queries do not work. Here is a working example with mapping
> and classes
>
> Cirlce, Square, Triangle all implement IShape. ToyBox entity has a
> property called Shape.
>
>     public class Circle : IShape
>     {
>         public virtual int Id { get; set; }
>         public virtual string Color { get; set; }
>     }
>
>     public class Square : IShape
>     {
>         public virtual int Id { get; set; }
>         public virtual string Color { get; set; }
>     }
>
>     public class Triangle : IShape
>     {
>         public virtual int Id { get; set; }
>         public virtual string Color { get; set; }
>     }
>
>     public class ToyBox
>     {
>         public virtual int Id { get; set; }
>         public virtual string Name { get; set; }
>         public virtual IShape Shape { get; set; }
>     }
>
> <?xml version="1.0" encoding="utf-8" ?>
> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test"
> namespace="Test">
>
>   <class name="Circle" table="circles">
>     <id column="circle_id" name="Id" type="int">
>       <generator class="identity"/>
>     </id>
>     <property name="Color" column="color"  />
>   </class>
>
>   <class name="Square" table="squares">
>     <id column="square_id" name="Id" type="int">
>       <generator class="identity"/>
>     </id>
>     <property name="Color" column="color"  />
>   </class>
>
>   <class name="Triangle" table="triangles">
>     <id column="triangle_id" name="Id" type="int">
>       <generator class="identity"/>
>     </id>
>     <property name="Color" column="color"  />
>   </class>
>
>   <class name="ToyBox" table="toyBox">
>     <id column="toybox_id" name="Id" type="int">
>       <generator class="identity"/>
>     </id>
>     <property name="Name" column="name"  />
>     <any name="Shape" id-type="int" meta-type="int">
>       <meta-value value="1" class="Circle"/>
>       <meta-value value="2" class="Square"/>
>       <meta-value value="3" class="Triangle"/>
>       <column name="s_object_id" not-null="true"/>
>       <column name="object_id" not-null="true"/>
>     </any>
>   </class>
> </hibernate-mapping>
>
> I can get a ToyBox by ID and when I look at the Shape Property its
> hydrated properly.
>
> BUT I can not query on Shape. The below query fails
>
> var entity = Session.Query<ToyBox>().Where(x => x.Shape is
> Circle).FirstOrDefault();
>
> Error:
> System.NullReferenceException: Object reference not set to an instance
> of an object.
>         at
> NHibernate.Hql.Ast.ANTLR.SessionFactoryHelperExtensions.FindSQLFunction(String
> functionName)
>         at NHibernate.Hql.Ast.ANTLR.Tree.IdentNode.get_DataType()
>         at
> NHibernate.Hql.Ast.ANTLR.Tree.BinaryLogicOperatorNode.ExtractDataType(IASTNode
> operand)
>         at NHibernate.Hql.Ast.ANTLR.Tree.BinaryLogicOperatorNode.Initialize()
>         at
> NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.PrepareLogicOperator(IASTNode
> operatorNode)
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.comparisonExpr()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.logicalExpr()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.whereClause()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectStatement()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.statement()
>         at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate()
>         at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String
> collectionRole)
>         at
> NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2
> replacements, Boolean shallow, String collectionRole)
>         at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2
> replacements, Boolean shallow)
>         at
> NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode
> ast, String queryIdentifier, String collectionRole, Boolean shallow,
> IDictionary`2 filters, ISessionFactoryImplementor factory)
>         at
> NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String
> queryIdentifier, IQueryExpression queryExpression, String
> collectionRole, Boolean shallow, IDictionary`2 filters,
> ISessionFactoryImplementor factory)
>         at
> NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String
> expressionStr, IQueryExpression queryExpression, String
> collectionRole, Boolean shallow, IDictionary`2 enabledFilters,
> ISessionFactoryImplementor factory)
>         at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String
> expressionStr, IQueryExpression queryExpression, String
> collectionRole, Boolean shallow, IDictionary`2 enabledFilters,
> ISessionFactoryImplementor factory)
>         at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String
> expressionStr, IQueryExpression queryExpression, Boolean shallow,
> IDictionary`2 enabledFilters, ISessionFactoryImplementor factory)
>         at
> NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression
> queryExpression, Boolean shallow, IDictionary`2 enabledFilters)
>         at
> NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression
> queryExpression, Boolean shallow)
>         at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression
> queryExpression)
>         at NHibernate.Linq.NhQueryProvider.Execute(Expression expression)
>         at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression
> expression)
>         at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
>         DogRepositoryTests.cs(32,0): at
> NHibernateScratchpad.Tests.ToyBoxRepositoryTests.Test()
>
> On Sep 9, 7:19 pm, Fabio Maulo <[email protected]> wrote:
>
> > I like the classes named "1" and "2"
>
> > --
> > Fabio Maulo
>
> > El 09/09/2010, a las 17:45, MichaelK <[email protected]> escribió:
>
> > > Is it possible to query an <Any/> collection by the type. Take the
> > > pretend Any mapping below. Can I find all Circles in the ToyBox using
> > > linq?
>
> > > <class name=ToyBox >
> > > <any name="Items" meta-type="int" id-type="int">
> > >        <meta-value class="1" value="Square"/>
> > >        <meta-value class="2" value="Circle"/>
> > >        <column name="entityTypeId"/>
> > >        <column name="entityId"/>
> > >      </any>
> > > </class>
>
> > > Here is how I would have hoped to query it.
>
> > > Session.Query<ToyBox>().Where(x => x.Items.GetType() ==
> > > typeof(Circle))
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "nhusers" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to 
> > > [email protected].
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/nhusers?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to