简体   繁体   English

IList的流畅NHibernate映射 <int> ?

[英]Fluent NHibernate mapping for IList<int>?

I'm using Fluent NHibernate 2.0.3 with NHibernate 4.0.0.4000 Backend DB is Sqlite. 我正在将Fluent NHibernate 2.0.3与NHibernate 4.0.0.4000一起使用,后端数据库是Sqlite。

My entity and mapping is defined as this: 我的实体和映射定义如下:

public class PriceHistory
{
    public virtual int ID { get; set; }
    public virtual IList<long> Date { get; set; }
    public virtual IList<float> Price { get; set; }
    public virtual IList<int> Volume { get; set; }
    public virtual float MinPrice { get; set; }
    public virtual float MaxPrice { get; set; }
}

class PriceHistoryMap : ClassMap<PriceHistory>
{
    public PriceHistoryMap()
    {
        Table("PriceHistories");
        Id(x => x.ID);
        HasMany<long>(x => x.Date);
        HasMany<float>(x => x.Price);
        HasMany<int>(x => x.Volume);
        Map(x => x.MinPrice);
        Map(x => x.MaxPrice);
    }   
}

When I try to start the application I get this exception: 当我尝试启动应用程序时,出现以下异常:

Association references unmapped class: System.Int64

It doesn't matter if I have int, long or float. 我是否有int,long或float都没有关系。 I always get an exception, as if I have to define the mapping for every basic value type. 我总是会遇到异常,好像我必须为每种基本值类型定义映射一样。

Whats wrong here? 怎么了 Whats the correct mapping for Lists of value types? 值类型列表的正确映射是什么?

I believe you might have to have it as HasMany<int>(x => x.Volume).Element("Value"); 我相信您可能必须将其作为HasMany<int>(x => x.Volume).Element("Value");

This post might also help with your question 这篇文章也可能对您的问题有所帮助

I don't know for sure, but it sounds like your floats, ints, and longs live in a different table? 我不确定,但这听起来像是您的浮动,整数和多头寿命在另一张桌子上?

If that's the case, you may have to set up a HasMany relationship for each, like so: 如果是这样,您可能必须为每个对象建立一个HasMany关系,如下所示:

HasMany<int>(x => x.Volume)
    .Table("PriceHistoryVolumes")
    .KeyColumn("PriceHistoryID")
    .Element("Volume");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM