Free display of NHibernate IList <Point> as a value for a single column
I have this class:
public class MyEntity
{
public virtual int Id { get; set; }
public virtual IList<Point> Vectors { get; set; }
}
How can I map Vectorsin Fluent NHibernate to a single column (as a value)? I thought about it:
public class Vectors : ISerializable
{
public IList<Point> Vectors { get; set; }
/* Here goes ISerializable implementation */
}
public class MyEntity
{
public virtual int Id { get; set; }
public virtual Vectors Vectors { get; set; }
}
Is it possible to map Vectorsas follows, hoping that Fluent NHibernate initializes the class Vectorsas a standard ISerializable?
Or how else could I map IList<Point>to a single column? I think I will have to write serialization / deserialization procedures myself, which is not a problem, I just need to tell FNH to use these procedures.
I assume that I should use IUserTypeor ICompositeUserType, but I do not know how to implement them, and how to inform FNH about cooperation.
.: -)
UserTypeConvention<T> at:
http://wiki.fluentnhibernate.org/Available_conventions
.
:
http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx
, :
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> :
http://jagregory.com/writings/fluent-nhibernate-auto-mapping-type-conventions/
:
public class ReplenishmentDayTypeConvention : ITypeConvention
{
public bool CanHandle(Type type)
{
return type == typeof(ReplenishmentDay);
}
public void AlterMap(IProperty propertyMapping)
{
propertyMapping
.CustomTypeIs<ReplenishmentDayUserType>()
.TheColumnNameIs("RepOn");
}
}
ReplenishmentDayUserType IUserType - , ReplenishmentDay - , .
:
autoMappings
.WithConvention(convention =>
{
convention.AddTypeConvention(new ReplenishmentDayTypeConvention());
// other conventions
});