Querying documents based on inherited entities

19 views
Skip to first unread message

Bill Bassler

unread,
May 22, 2012, 8:23:01 AM5/22/12
to rav...@googlegroups.com
Concerning the following (abbreviated) inherited structure supported with respect to query in Raven
 
    public class YesNoPendingType : Enumeration
    {
        public static readonly YesNoPendingType Pending = new YesNoPendingType(0, "Pending");
        public static readonly YesNoPendingType Yes = new YesNoPendingType(1, "Yes");
        public static readonly YesNoPendingType No = new YesNoPendingType(2, "No");
        public YesNoPendingType()
        {
        }
        private YesNoPendingType(int value, string name)
            : base(value, name)
        {
        }
    }
 
    public abstract class Enumeration
    {
        private readonly int value;
        private readonly string name;
        protected Enumeration()
        {
        }
        protected Enumeration(int value, string name)
        {
            this.value = value;
            this.name = name;
        }
        public int Value
        {
            get { return value; }
        }
        public string Name
        {
            get { return name; }
        }
    }
 
The YesNoPendingType is embedded in a containing entity and is persisted.

{

  "DoesApplicantHaveHousing": {

    "Value": 0,

    "Name": "Pending"

  },

 

Querying against session Load directly returns the base Enumeration type within the containing entity with Value and Name data functions as expected. Name and Value are populated.

var atp = session.Load<PreAtpQuestionnaire>(key);

However, when querying against a Raven Unit of Work based repository the type returned is the YesNoPendingType and Name and Value are null.

Is this kind of inheritence scenario supported by Raven? I'm not able to see any apparent difference between the two retrievals but the results are different.

 

Itamar Syn-Hershko

unread,
May 22, 2012, 8:27:39 AM5/22/12
to rav...@googlegroups.com
Use auto properties and it will work:

    public abstract class Enumeration 
    {
        protected Enumeration()
        {
        }
        protected Enumeration(int value, string name)
        {
            Value = value;
            Name = name;
        }
        public int Value
        {
            get; set;
        }
        public string Name
        {
            get; set;
        }
    }

But why aren't you using a simple enum?

Chris Marisic

unread,
May 22, 2012, 8:32:22 AM5/22/12
to rav...@googlegroups.com
My guess is because you can't do

void somemethod<T>() where T : myenum

without resorting to lots of IL magic

Bill Bassler

unread,
May 22, 2012, 8:33:38 AM5/22/12
to rav...@googlegroups.com
There is probable need for additional properties for the items.

Itamar Syn-Hershko

unread,
May 22, 2012, 8:36:37 AM5/22/12
to rav...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages