Nested maps

igitur's Avatar

igitur

07 Jul, 2010 09:18 AM via web

Hi,

I have a database table with Sqlite structure:

CREATE TABLE Cashflows
(
    Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    Fund_Id INTEGER NOT NULL,
    CashflowDate DATETIME NOT NULL,
    CashflowType INTEGER NOT NULL,
    CashflowValue DOUBLE NOT NULL
);

Fund_Id is just a standard reference to the Fund table.

In Fluent NHibernate, I'd like to map it in such a way that I can set up the domain to do lookups like this:

double cashflowValue = Fund.Cashflows[DateTime.Today][CashflowTypes.Normal].CashflowValue;

So I guess I have to use some kind of nested Map.

Alternatively, I can create a CashflowKey class:

public class CashflowKey
{
    public virtual DateTime CashflowDate {get; set;}
    public virtual CashflowTypes CashflowType {get; set;}
}

And do lookups as follows:

CashflowKey key = new CashflowKey() {
    .CashflowDate = DateTime.Today,
    .CashflowType = CashflowTypes.Normal };

double cashflowValue = Fund.Cashflows[key].CashflowValue;

Any of the two solutions is acceptable. However, I've been unable to map this successfully with Fluent NHibernate. I've tried Entity Maps, Components and everything else that I could think of. Is this scenario possible to solve with FH?

  1. 2 Posted by igitur on 07 Jul, 2010 09:20 AM

    igitur's Avatar

    I see this thread is marked as private. I didn't mark it as such. Odd.

  2. Support Staff 3 Posted by Paul Batum on 07 Jul, 2010 11:05 AM

    Paul Batum's Avatar

    I haven't seen a map of maps before when working with nhibernate, but I
    would guess you can do it, though I'm not sure how exactly.

    Have you tried asking on the nhibernate
    users<http://groups.google.com/group/nhusers/> mailing
    list? If they can show you the necessary xml, we can try to assist you with
    the fluent version.

  3. 4 Posted by igitur on 07 Jul, 2010 11:10 AM

    igitur's Avatar

    Thanks. I'll ask in that group.

    How about the 2nd possibility of doing lookups with a key (which has
    multiple fields)?

  4. Support Staff 5 Posted by Paul Batum on 07 Jul, 2010 11:44 AM

    Paul Batum's Avatar

    The second option strikes me as being more unlikely. If I was trying to
    implement this I would focus mostly on the first option.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What comes next? 'Monday Tuesday Wednesday ?????'