Search code examples
c#ormfluent-nhibernatemapping

Fluent nhibernate Automaping by property name


Is there a way to map properties of an entity automatically to column names (without code)

Class Person
{
  public int ID{get;set;}
  public string NAME {get;set;}
}

What I would like is to map this class to table PERSON(ID,NAME) without doing it explicitly in code or xml


Solution

  • When your properites have the same name like the columns in the table you can use

    Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssembly(
                        Assembly.GetAssembly(typeof(MyEntityType))
                        ));
    

    it will automap all classes in the given assembly.