Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Fluent nhibernate 列属性自动映射_Fluent Nhibernate_Nhibernate Mapping_Automapping - Fatal编程技术网

Fluent nhibernate 列属性自动映射

Fluent nhibernate 列属性自动映射,fluent-nhibernate,nhibernate-mapping,automapping,Fluent Nhibernate,Nhibernate Mapping,Automapping,不可能为列命名创建约定: 我有一段代码: public AutoPersistenceModel Generate() { var result = AutoPersistenceModel.MapEntitiesFromAssemblyOf<User>() .Where(GetAutoMappingFilter) .WithConvention(GetConventions); return result; } private b

不可能为列命名创建约定:

我有一段代码:

public AutoPersistenceModel Generate()
{
    var result = AutoPersistenceModel.MapEntitiesFromAssemblyOf<User>()
        .Where(GetAutoMappingFilter)
        .WithConvention(GetConventions);

    return result;
}

private bool GetAutoMappingFilter(Type t)
{
    return
        t.GetInterfaces().Any(
            x => x.IsGenericType && (x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>)));
}


private static void GetConventions(Conventions conventions)
{
    conventions.GetPrimaryKeyNameFromType = type => type.Name.ToLower() + "_id";
    conventions.FindIdentity = type => type.Name.ToLower() == "id";
    conventions.GetTableName = type =>
        {
            if (!type.Name.Contains("Lookup"))
            {
                return Inflector.Net.Inflector.Pluralize(type.Name).ToLower();
            }
            return Inflector.Net.Inflector.Underscore(type.Name)
                .Replace("lookup", "lu").ToLower();
        };
    conventions.IsBaseType = DontMapAsJoinedSubclassTypesInheritedFrom;
    conventions.GetForeignKeyNameOfParent = type => Inflector.Net.Inflector.Underscore(type.Name) + "_id";
    conventions.GetForeignKeyName = type => Inflector.Net.Inflector.Underscore(type.Name) + "_id";
    conventions.OneToManyConvention = m => m.Cascade.All();

}


private static bool DontMapAsJoinedSubclassTypesInheritedFrom(Type arg)
{
    var derivesFromEntity = arg == typeof(Entity);
    var derivesFromEntityWithTypedId = arg.IsGenericType &&
        (arg.GetGenericTypeDefinition() == typeof(EntityWithTypedId<>));
    return derivesFromEntity || derivesFromEntityWithTypedId;
}
谢谢

public class Organisation : EntityWithTypedId<int>
{
    public virtual Organisation Parent { get; set; }
    public virtual LookOrganisationType OrganisationType { get; set; }
    [DomainSignature]
    public virtual string OrganisationName { get; set; }
    public virtual string Address1 { get; set; }
    public virtual string Address2 { get; set; }
    public virtual string City { get; set; }
    public virtual string Postcode { get; set; }
    public virtual LookupCountry Country { get; set; }
    public virtual string TelNo { get; set; }
    public virtual string FaxNo { get; set; }
    public virtual string Email { get; set; }
    public virtual User Contact { get; set; }
    public virtual DateTime? DateCreated { get; set; }
    public virtual DateTime? DateAmended { get; set; }
    public virtual bool Active { get; set; }
}
(conventions.GetPropertyName = type => Inflector.Net.Inflector.Underscore(type.ColumnName))