Fluent NHibernate mapping IList<Point> as value to single column

☆樱花仙子☆ 提交于 2019-12-06 03:38:57

Found an answer. :-)

Heading UserTypeConvention<T> at:
http://wiki.fluentnhibernate.org/Available_conventions
for custom type conversions.

This is for implementing custom type convertors:
http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx

Additional related links I've found:
http://www.lostechies.com/blogs/rhouston/archive/2008/03/23/mapping-strings-to-booleans-using-nhibernate-s-iusertype.aspx
http://www.martinwilley.com/net/code/nhibernate/usertype.html
http://geekswithblogs.net/opiesblog/archive/2006/08/13/87880.aspx
http://kozmic.pl/archive/2009/10/12/mapping-different-types-with-nhibernate-iusertype.aspx
http://blogs.msdn.com/howard_dierking/archive/2007/04/23/nhibernate-custom-mapping-types.aspx

UserTypeConvention<T> usage:
http://jagregory.com/writings/fluent-nhibernate-auto-mapping-type-conventions/

The most important code in last link is this:

public class ReplenishmentDayTypeConvention : ITypeConvention
{
  public bool CanHandle(Type type)
  {
    return type == typeof(ReplenishmentDay);
  }

  public void AlterMap(IProperty propertyMapping)
  {
    propertyMapping
      .CustomTypeIs<ReplenishmentDayUserType>()
      .TheColumnNameIs("RepOn");
  }
}

Where ReplenishmentDayUserType is IUserType-derived class and ReplenishmentDay is the class, which should be converted using your user type converter.

And this:

autoMappings
  .WithConvention(convention =>
  {
    convention.AddTypeConvention(new ReplenishmentDayTypeConvention());
    // other conventions
  });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!