开发者

Fluent Nhibernate - Collection name naming convention

开发者 https://www.devze.com 2023-01-12 09:30 出处:网络
Is it possible to set a naming convention for all collection of an entity even if I use the Access Strategy or not, so that all collection names are {EnityName}s instead of {entityName}s (because of A

Is it possible to set a naming convention for all collection of an entity even if I use the Access Strategy or not, so that all collection names are {EnityName}s instead of {entityName}s (because of Access.CamelCaseField(Prefix.Underscore) the first letter is lower)?

Or is there a way where I can tell NHibernate that it shall use the associationPath case insensitive in the SetF开发者_StackOverflow社区etchMode method?

This method is not case insensitive:

ICriteria SetFetchMode(string associationPath, FetchMode mode)

I try to build a type safe way of setting the associationPath

EDIT:

The associationPath is the name attribute of the collection.

<set access="field.camelcase-underscore" cascade="save-update" inverse="true" lazy="true" name="employees" table="TeamEmployee" mutable="true">

I want to define a naming convention for the name attribute.

EDIT:

I found something like this:

public class LowercaseCollectionNameConvention : IClassConvention
{
    public void Apply(IClassInstance instance)
    {
        instance.Collections. ...
    }
}

Does someone one know how to use this?


I am not sure I fully understand the context of your question. If you are after a naming strategy for the relationship during mapping and schema generation then you need to do some sort of "Convention".

I recently blogged my conventions http://blog.zoolutions.se/post/2010/07/03/Inflector-e28093-renaming-utilities.aspx and http://blog.zoolutions.se/post/2010/07/05/All-my-current-Fluent-NHibernate-Conventions.aspx

If you could add some better description I'll be happy to extend my answer.

EDIT The following should get you pretty close if you copy the Inflektor class from my blog or any other location it can be found:

public class HasManyConvention : IHasManyConvention
{
    public void Apply(IOneToManyCollectionInstance instance)
    {
        instance.Cascade.SaveUpdate();
        instance.Inverse();
        string pluralized = Inflector.Pluralize(instance.ChildType.Name);
        instance.Name(pluralized.ToLower());
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号