NHibernate: cannot resolve inherited id property

混江龙づ霸主 提交于 2020-01-04 04:53:08

问题


I have the entity defined below:

public class Foo : Entity<Foo.FooId>
{
    public class FooId
    {
        public virtual String Bar { get; protected internal set; }
        public virtual Int32 Buzz { get; protected internal set; }
    }

    // ...
}

And here's the base class:

public abstract class Entity<T> : IEquatable<Entity<T>>
{
    public virtual T Id { get; protected internal set; }

    // ...
}

I'm going to map the "Id" property as a "composite key", so I've added the following mapping class:

public class FooMap : ClassMapping<Foo>
{
    public FooMap()
    {
        ComponentAsId(x => x.Id, m =>
        {
            m.Property(p => p.Bar);
            m.Property(p => p.Buzz);
        });
    }
}

And that's all pretty nice, but I get an error with the following querying attempt:

session.QueryOver<Foo>()
       .Where(m => m.Id.Bar == "a" &&
                   m.Id.Buzz == 2).List();

The error I get is: NHibernate.QueryException : could not resolve property: Id of: Foo

It's quite strange, because by removing the base class and encapsulating everything within "Foo", it works like a charm. Thanks in advance.


回答1:


This was a bug and reported as NH-3105. It is now fixed in the most recent of the source code and will be released as 3.3.3.GA.



来源:https://stackoverflow.com/questions/14254578/nhibernate-cannot-resolve-inherited-id-property

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!