NHibernate component with a one-to-many relation from parent

这一生的挚爱 提交于 2020-01-06 09:30:09

问题


Say I have a Queue table and a Job table. In the Job table there is a foreign key column QueueId for the Queue table, i.e.

Queue.Id <-- Job.QueueId

Using Fluent NHibernate it is pretty straightforward to map this to a property in the Queue class, i.e.

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

But assume I have a very good reason to have a class inbetween, 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 a 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 as to what I'm doing wrong...


回答1:


Solved. This was caused by a mapping problem in the JobMap.



来源:https://stackoverflow.com/questions/1241897/nhibernate-component-with-a-one-to-many-relation-from-parent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!