功能NHibernate映射的IList<点>作为价值单列价值、功能、NHibernate、IList

由网友(人走茶凉)分享简介:我有这个类:public class MyEntity{public virtual int Id { get; set; }public virtual IList Vectors { get; set; }}在向量在功能NHibernate 如何映射到一个单一的列(如值)?我在想这样的:How...

我有这个类:

public class MyEntity
{
    public virtual int Id { get; set; }
    public virtual IList<Point> Vectors { get; set; }
}

向量在功能NHibernate

如何映射到一个单一的列(如值)?我在想这样的:

How can I map the Vectors in Fluent NHibernate to a single column (as value)? I was thinking of this:

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; }
}

是否有可能映射向量这样,希望流利的NHibernate将初始化向量类为标准了ISerializable ?

Is it possible to map the Vectors like this, hoping that Fluent NHibernate will initialize Vectors class as standard ISerializable?

或者我怎么回事,可以映射的IList&LT;点&GT; 来一列?我想我会写的序列化/反序列化例程自己,这不是问题,我只需要告诉FNH使用这些程序。

Or how else could I map IList<Point> to a single column? I guess I will have to write the serialization/deserialization routines myself, which is not a problem, I just need to tell FNH to use those routines.

我想我应该用 IUserType ICompositeUserType ,但我不知道如何实现它们,以及如何告诉FNH合作。

I guess I should use IUserType or ICompositeUserType, but I have no idea how to implement them, and how to tell FNH to cooperate.

推荐答案

找到答案。 : - )

Found an answer. :-)

标题 UserTypeConvention&LT; T&GT; 为: http://wiki.fluentnhibernate.org/Available_conventions 自定义类型转换。

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

这是实现自定义类型转换器: http://intellect.dk/post/Implementing-custom-types-in -nHibernate.aspx

This is for implementing custom type convertors: 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/$c$c /nhibernate/usertype.html http://geekswithblogs.net/opiesblog/archive/2006/08/13 /878​​80.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

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&LT; T&GT; 用法: http://jagregory.com/writings/fluent-nhibernate-auto-映射型约定/

最重要的code在最后一个环节是这样的:

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");
  }
}

其中, ReplenishmentDayUserType IUserType 派生类和 ReplenishmentDay 是类,应使用用户的类型转换器转换。

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

和这样的:

autoMappings
  .WithConvention(convention =>
  {
    convention.AddTypeConvention(new ReplenishmentDayTypeConvention());
    // other conventions
  });
阅读全文

相关推荐

最新文章