我有这门课:
public class MyEntity
{
public virtual int Id { get; set; }
public virtual IList<Point> Vectors { get; set; }
}
我怎样才能绘制地图Vectors
在 Fluent NHibernate 中到单个列(作为值)?我在想这个:
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; }
}
是否可以绘制地图Vectors
像这样,希望 Fluent NHibernate 能够初始化Vectors
类作为标准 ISerialized?
或者我还能怎么映射IList<Point>
到单个列?我想我必须自己编写序列化/反序列化例程,这不是问题,我只需要告诉 FNH 使用这些例程。
我想我应该使用IUserType
or ICompositeUserType
,但我不知道如何实施它们,以及如何告诉FNH合作。
找到了答案。 :-)
Heading UserTypeConvention<T>
at:
http://wiki. Fluentnhibernate.org/Available_conventions http://wiki.fluentnhibernate.org/Available_conventions
用于自定义类型转换。
这是为了实现自定义类型转换器:
http://intellect.dk/post/Implementing-custom-types-in-nHibernate.aspx 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.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://www.martinwilley.com/net/code/nhibernate/usertype.html
Link https://web.archive.org/web/20210127201844/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://kozmic.pl/archive/2009/10/12/mapping-different-types-with-nhibernate-iusertype.aspx
Link https://web.archive.org/web/20100516024604/http://blogs.msdn.com:80/howard_dierking/archive/2007/04/23/nhibernate-custom-mapping-types.aspx
UserTypeConvention<T>
usage:
http://jagregory.com/writings/ Fluent-nhibernate-auto-mapping-type-conventions/ 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");
}
}
Where ReplenishmentDayUserType
is IUserType
-派生类和ReplenishmentDay
是类,应该使用用户类型转换器进行转换。
和这个:
autoMappings
.WithConvention(convention =>
{
convention.AddTypeConvention(new ReplenishmentDayTypeConvention());
// other conventions
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)