So no ideas from anyone?

On Sep 11, 8:29 am, MAMMON <[EMAIL PROTECTED]> wrote:
> I have a program I'm working on that creates CRUD unit tests for each
> of the mapped classes in my data access layer.  Properties that map
> directly to fields in the database table are working fine, but
> collections are trickier.
>
> I'm currently using SessionFactory.GetAllCollectionMetadata() to
> return an IDictionary of all mapped collections' metadata.  When
> creating tests for a particular type, I go through that IDictionary
> looking for collections that belong to the class I'm generating unit
> tests for.  Each DictionaryEntry's Value is an
> AbstractCollectionPersister object.
>
> Here's a snippet of my problem area:
>
> foreach (DictionaryEntry entry in m_collectionMetadata)
> {
>         AbstractCollectionPersister acp =
> (AbstractCollectionPersister)entry.Value;
>         Type parentType = acp.OwnerEntityPersister.EntityMetamodel.Type;
>
>                 // Is the type that "owns" this collection our type (m_type)?
> (i.e., is this collection in our class?)
>                 if (!m_type.Equals(parentType))
>                         continue;
>
>                 // Get the "child" type (this is a collection of WHAT?)
>                 Type childType = acp.ElementType.ReturnedClass;
>
> .....
>
> All of that works fine.  It successfully grabs the correct parent and
> child types (by parent, I mean the class that contains the collection,
> and by child, I mean the type of object the collection holds).  To
> generate source code, I need to know 2 things:
>
> 1. The name of the collection in the parent class
> 2. The name of the property in the child class that is a reference to
> its parent object.
>
> I have the first one figured out; it's the
> AbstractCollectionPersister.Name property (though that value is fully
> qualified, as in "My.Namespace.Classname.CollectionName", so I just
> grab the last part, "CollectionName").
>
>     string collectionName =
> acp.Name.Substring(acp.Name.LastIndexOf(".") + 1);
>
> But I can't figure out the 2nd part.  I've spent over an hour looking
> at the quick watch window while debugging, to explore all of the
> properties of the AbstractCollectionPersister, and I can't find
> anything that has the name of the property in the child class.  I
> realize that it isn't technically a part of the collection, so I may
> be looking in the wrong spot, but the AbstractCollectionPersister
> exposes so many other objects related to both the parent and child
> types, and I don't know where else to look.
>
> Before someone suggests it, I can't use
> AbstractCollectionPersister.OwnerEntityName.  That's just the name of
> the class, and the property in the child class might not use the class
> name.
>
> Example (typing this out on the fly, may contain simple errors):
>
> class Parent
> {
>     private IList<Child> _children;
>     public IList<Child> Children { get...; set...; }
>
> }
>
> class Child
> {
>    private Parent _parent;
>    public Parent MyParent { get...; set...; }
>
> }
>
> The property name "MyParent" is different than the class name, so
> AbstractCollectionPersister.OwnerEntityName won't work, because it
> will contain the class name.  I need to find a way to get "MyParent",
> in a way that I know it is the "other side" of a collection (a
> child''s reference back to its parent).
>
> I know that the value will be in the
> AbstractCollectionPersister.ElementPersister.PropertyNames string
> array, but then I run into the problem of determining WHICH of the
> properties in the PropertyNames array is the correct one for any given
> collection.  I can't just go by the
> AbstractCollectionPersister.ElementPersister.PropertyNames array,
> because there could be more than 1 property of the same type, and I
> wouldn't know which name to use.
>
> So does anyone know how to (at runtime) find the name of the property
> in the child class that is a reference back to the Parent class that
> contains the collection of child objects?
--~--~---------~--~----~------------~-------~--~----~
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