I figured out the reason now. But it seems a bit weird.
Firstly, I want to extend ConventionModelMapper, which is quite hard to do.
Because I'm *not able to inject a custom IModelInspector into
ConventionModelMapper.*
But finally I copied the whole ConventionModelMapper to my project and add
IModelInspector as constructor parameter. So that's not a big problem.
Because it's not possible to override methods in SimpleModelInspector, so I
write a ConventionModelInspector to wrap it:
public class ConventionModelInspector : IModelInspector {
private SimpleModelInspector *_innerInspector*;
pubilc bool IsComponent(Type type) {
* if (my custom logic) {*
* return true;*
* }*
*return _innerInspector.IsComponent(type);*
}
}
Note that I have to do it this way. I can't simply change component
inspection logic by calling IsComponent(Func match),
because I just want to* add some logic before the
default inspection logic. *
*I don't want to completely replace the default inspection logic, cos** that
could be a huge amount of work.*
But the most weird thing is that,* if I do it this way, my manually added
conformist mapping will be ignored as I mentioned in the post.*
The solution is to make my ConventionModelInspector implement both
IModelInspector and IModelExplicitDeclarationsHolder.
And it seems that I can't use a separate IModelExplicitDeclarationsHolder
implementation.
*I must use one class to implement both IModelInspector
and IModelExplicitDeclarationsHolder like SimpleModelInspector does.*
This looks a bit weird.
Am I missing something? Thanks.
On Saturday, January 4, 2014 9:41:11 PM UTC+8, Mouhong Lin wrote:
>
> Hi,
>
> I'm using NHibernate 3.3.2.4000 I have this model:
>
> public class PageItem {
> // ...
> public virtual *EntityAttributeCollection Attributes *{ get; set; }
> }
>
> where the *EntityAttributeCollection *is defined as a collection:
>
> public class *EntityAttributeCollection *:
> IEnumerable<KeyValuePair<string, string>>
> {
> }
>
> *EntityAttributeCollection *is a custom user type.
> The *Attributes *collection will be saved in one column as json.
>
> I have a customized conformist mapping for this custom property:
>
> Property(c => c.Attributes, m => {
> *m.Type<EntityAttributeCollectionUserType>();*
> });
>
> *I assumed this manual property mapping will override the Bag mapping
> mapped by ConventionModelMapper.*
> But it didn't. When I run the app, it raised exception: *Can't determine
> collection element relation (property Attributes in PageItem)*
>
> After some debugging, it seems that, by convention, the Attributes
> property is mapped as Bag.
> *Event though I manually map Attributes as "Property", it won't override
> the convention Bag mapping.*
> I can use "Property" mapping to override conventional "Property" mapping.
> I also can use "Bag" mapping to override conventional "Bag" mapping.
> But I'm not able use "Property" mapping to override conventional "Bag"
> mapping.
>
> How can I override the conventional Bag mapping to make it a "Property"
> mapping? Thanks
>
>
--
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.