简体   繁体   中英

Fluent NHibernate mapping for IList<int>?

I'm using Fluent NHibernate 2.0.3 with NHibernate 4.0.0.4000 Backend DB is 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. 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");

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<int>(x => x.Volume)
    .Table("PriceHistoryVolumes")
    .KeyColumn("PriceHistoryID")
    .Element("Volume");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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