NHibernate Parent-to-Many Component

Suppose I have a Queue table and a Job table. The Job table has a QueueId foreign key column for the Queue table, i.e.

Queue.Id <- Job.QueueId

Using Fluent NHibernate, it is fairly simple to map this property to the Queue class, i.e.

/* QueueMap */ HasMany(x => x.Jobs) .KeyColumnNames.Add("QueueId"); 

But suppose I have a very good reason to have an intermediate class, say something like:

 public class Queue { public Group Group { get; set; } } public class Group { public IList<Job> Jobs { get; private set; } } 

Then I need to map this using Component, i.e.

 /* QueueMap */ Component( x => x.Group, y => y.HasMany(x => x.Jobs).KeyColumnNames.Add("QueueId") ); 

When I do this, I get the following:

 {"could not initialize a collection: [Queue.Group.Jobs#832fc413-c282-48e8-8cb6-d2a70b0b8de4] [SQL: SELECT values0_.QueueId as QueueId1_, values0_.Id as Id1_, values0_.Id as Id16_0_, (....) FROM dbo.Jobs values0_ WHERE values0_.QueueId=?]"} 

Any idea on what I'm doing wrong ...

0
source share
1 answer

solved. This was caused by a mapping problem in JobMap.

+1
source

All Articles