Yes I will add a bug. Thanks for the help.

On Sep 10, 2:07 pm, José F. Romaniello <[email protected]> wrote:
> oh i see now. I thought it was a collection, but you are right, it is just
> an any.. So sorry.
> It is a bug, would you mind to create an issue on jira?
>
> btw, I am pretty sure you can query this in hql,
>
> from ToyBox t where t.Shape.class = 'full type name'
>
> for instance;
>
> session.CreateQuery("from ToyBox t where t.Shape.class = :shapeClass")
>    .SetParameter("shapeClass", typeof(Circle).FullName)
>    .List<ToyBox>();
>
> (i prefer named queries, though)
>
> 2010/9/10 MichaelK <[email protected]>
>
> > In #3, your query will not work since its not an IEnumerable. Shape is
> > just a single object. I tried below test and I get different Error.
> > Looks like its not looking at Any mapping to get the meta-value value.
> > In this case Circle = 1.
>
> >        [Test]
> >        public void Test44()
> >         {
> >            var entity = Repository.Session.QueryOver<ToyBox>()
> >                 .Where(x => x.Shape.GetType() ==
> > typeof(Circle)).List();
> >            Assert.IsNotNull(entity);
> >        }
>
> > Execute
> >        NHibernate.Exceptions.GenericADOException: could not execute query
> >        [ SELECT this_.toybox_id as toybox1_5_0_, this_.name as name5_0_,
> > this_.s_object_id as s3_5_0_, this_.object_id as object4_5_0_ FROM
> > toyBox this_ WHERE this_.s_object_id = ? ]
> >        Positional parameters:  #0>Touchcom.Objects.Entities.Circle
> >        [SQL: SELECT this_.toybox_id as toybox1_5_0_, this_.name as
> > name5_0_,
> > this_.s_object_id as s3_5_0_, this_.object_id as object4_5_0_ FROM
> > toyBox this_ WHERE this_.s_object_id = ?] --->
> > System.InvalidCastException: Unable to cast object of type
> > 'System.RuntimeType' to type 'System.String'.
>
> > On Sep 10, 12:58 pm, José F. Romaniello <[email protected]>
> > wrote:
> > > 1-Yes it is a bug in the linq provider. You can submit a test case to the
> > > issue trackerhttp://jira.nhforge.org/
> > > 2-I dont like your QueryOver query Where(x => x.Shape == new Circle { Id
> > = 1})) ... Its feel just wrong.
>
> > > 3-In the first mail you said, "Can I find all Circles in the ToyBox
> > > using linq?" So I wonder if the query you are looking for is something
> > like
> > > this:
>
> > > session.Query<ToyBox>().Where(tb => tb.Id = someId...).Select(tb =>
> > > tb.Shape.OfType<Circle>()).First()...
>
> > > Or something like that?
> > > I don't know if this work, it could fail too... But i think this is the
> > > query you need.
>
> > > 2010/9/10 MichaelK <[email protected]>
>
> > > > Sorry for the mass updates but I keep getting closer. I got it working
> > > > with QueryOver, but Linq fails. I have two UnitTests below. One using
> > > > QueryOver<> that WORKS, and second using Linq that fails. Is this a
> > > > bug with the Linq provider??  Also note how I had to create a circle
> > > > as well for the query to work. I still would like to get all ToyBoxes
> > > > with Shape of type Circle.
>
> > > >        [Test]
> > > >        public void Test()
> > > >        {
> > > >            var entity = Repository.Session.QueryOver<ToyBox>()
> > > >                .Where(x => x.Shape == new Circle { Id =
> > > > 1 }).SingleOrDefault();
> > > >            Assert.IsNotNull(entity);
> > > >        }
>
> > > >        [Test]
> > > >        public void Test1()
> > > >        {
> > > >            var entity = Repository.Session.Query<ToyBox>()
> > > >                .Where(x => x.Shape == new Circle { Id =
> > > > 1 }).SingleOrDefault();
> > > >            Assert.IsNotNull(entity);
> > > >         }
>
> > > > On Sep 10, 12:18 pm, MichaelK <[email protected]> wrote:
> > > > > 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
>
> ...
>
> read more »

-- 
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