Hi there. 

So i use NHibernate 3.3.3 and have a class mapping that uses the "Any type 
mappings" described in 5.2.4 of the NHibernet documentation. 

It currently looks like this: 

  <class name="AttributeValue" table="AttributValue">
    <id name="Id" column="ID" type="int" >
      <generator class="MyGenerator" />
    </id>
    <property   name="Value"    column="Value"      type="string" 
length="255"/>
    <many-to-one name="AttributeDef" column="AttributDef_ID" />

    <any name="Reference" id-type="Int32" meta-type="Int32">
      <meta-value value="1" class="MxObject"/>
      <meta-value value="500" class="Material"/>
      <meta-value value="5" class="Company"/>
      <meta-value value="10" class="Fluid"/>
      <meta-value value="10040" class="Contract"/>
      <meta-value value="504" class="Tool"/>
      
      <column name="Kontext"/>
      <column name="Oid"/>
    </any>
  </class>

My entity looks like this: 

    public class AttributeValue
    {
        public AttributeValue() { }
        public virtual int Id { get; set; }
        public virtual string Value { get; set; }
        public virtual AttributeDef AttributeDef { get; set; }
        public virtual object Reference { get; set; }     
    } 

The other entities referenced in the <any/> mapping have a collection that 
points to the AttributeValue Entity like this:

        public virtual ICollection<AttributeValue> AttributeValueList { 
get; set; }

And the mapping looks like this: 

    <bag name="AttributeValueList">
      <key column="OID"/>
      <one-to-many class="AttributeValue"/>
    </bag>

Everything is working as intended. I can query all the stuff i need, i can 
write it just fine. 

Here is my problem. I'm writing a test that takes every entity in my model 
and writes a dummy version with random data to the database using 
reflection. Everything works fine up until i hit that 

        public virtual object Reference { get; set; }

property of the AttributeValue entity. 

I just don't know how to figure how to query the metadata or the mapping to 
find out what possible entities to put into that Reference property. 

I tried to get the meta-values this way: 

        var metadata = session.SessionFactory.GetClassMetadata(t);
        var pType = metadata.GetPropertyType(p.Name) as AnyType;
        var mType = (pType.Subtypes[0]) as MetaType;

But the MetaType class doesn't expose the dictionaries holding that 
particular information and i don't really see a way to just get a list of 
possible classes out of it. 

I also tried it via the cfg.GetClassMapping(typeof (AttributeValue)) route 
but i only end up getting an instance of the MetaType class again.

Is there a way to query that particular information?

If not maybe there's another way?

I found in the NHibernate documentation this example: 

<any name="AnyEntity" id-type="Int64" meta-type="Eg.Custom.Class2TablenameType">
    <column name="table_name"/>
    <column name="id"/>
</any>


If i see that right then i could make a class that holds this information 
and pass it on as the meta-type attribute. I then could just query that 
class to get the information i want. 

I just don't know how to implement this Class2TablenameType class and the 
documentation isn't really clear on it (at least i don't really understand 
it) how to do it. 

Help would be appreciated. 



-- 
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/groups/opt_out.

Reply via email to