Override default Fluent NHibernate Column Mapping

2019-07-17 21:20发布

问题:

I am trying to find the syntax for changing the automap behavior of Fluent NHibernate.

How would I modify the code below to map the UserId property to a column named UserIdentifier (as an example)?

public class MyTypeMap : ClassMap<MyType>
{
    public MyTypeMap()
    {
            Table("MyTypes");
            Id(x => x.InstanceId).GeneratedBy.Guid().UnsavedValue(Guid.Empty);
            Map(x=> x.UserId);
    }
}

Thanks

回答1:

public class MyTypeMap : ClassMap<MyType>
{
    public MyTypeMap()
    {
            Table("MyTypes");
            Id(x => x.InstanceId).GeneratedBy.Guid().UnsavedValue(Guid.Empty);
            Map(x=> x.UserId).Column("UserIdentifier");
    }
}


回答2:

public class MyTypeMap : ClassMap<MyType>
{
   public MyTypeMap()
   {
        Id (x => x.InstanceId).Column ("UserIdentifier").GeneratedBy.Guid().UnsavedValue(Guid.Empty);
   }
}