Remapping properties in inheritance map class

77 views
Skip to first unread message

Adel F

unread,
Apr 14, 2012, 4:32:42 AM4/14/12
to fluent-n...@googlegroups.com
I have a base map class(in its own assembly), where Segment property was declared as LazyLoad.
public class GroupMap : ClassMap<Group>
{
   
public GroupMap()
   
{
       
....

       
Map(x => x.Segment)
           
.LazyLoad();
   
}
}

In my application I want this property not to be a LazyLoad. I tried some methods like this:

public class MyGroupMap : GroupMap
{
   
public MyGroupMap() : base()
   
{
       
Map(x => x.Segment)
           
.Not.LazyLoad();
   
}
}

And Adding this class to Mappings. But it only generates a runtime exception(Property Segment was already mapped. Obvious). Any suggestions? I think Properties property might help, but it is deprecated.

Geoff Bennett

unread,
Apr 15, 2012, 3:54:17 AM4/15/12
to fluent-n...@googlegroups.com
I would say have a base class that has all the mappings except for this one in it, then a subclass of that base class that has the default LazyLoad mapping for the Segment property. Then, in your MyGroupMap subclass, you could change the lazy loading. Something like this:

// Maps all properties _except_ the Segment
public class GroupMapBase : ClassMap<Group>
{
    public GroupMapBase()
    {
        Map(x => x.ThisProperty);
        Map(x => x.ThatProperty);
    }
}

// Adds a default Segment property mapping.
public class GroupMap : GroupMapBase
{
    public GroupMap()
    {
        Map(x => x.Segment)
            .LazyLoad();
    }
}

// Adds the specialised Segment property mapping.
public class MyGroupMap : GroupMapBase
{
    public MyGroupMap()
    {
        Map(x => x.Segment)
            .Not.LazyLoad();
    }
}

Not sure if it's the best way, but it's the first one that springs to mind.

Thanks,
Geoff.

--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To view this discussion on the web visit https://groups.google.com/d/msg/fluent-nhibernate/-/-5AbXPY55bQJ.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

Adel F

unread,
Apr 16, 2012, 7:37:40 AM4/16/12
to fluent-n...@googlegroups.com
Good idea. Thank you, Geoff.
Reply all
Reply to author
Forward
0 new messages