Nested maps
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?
2 Posted by igitur on 07 Jul, 2010 09:20 AM
I see this thread is marked as private. I didn't mark it as such. Odd.
Support Staff 3 Posted by Paul Batum on 07 Jul, 2010 11:05 AM
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.
4 Posted by igitur on 07 Jul, 2010 11:10 AM
Thanks. I'll ask in that group.
How about the 2nd possibility of doing lookups with a key (which has
multiple fields)?
Support Staff 5 Posted by Paul Batum on 07 Jul, 2010 11:44 AM
The second option strikes me as being more unlikely. If I was trying to
implement this I would focus mostly on the first option.