简体   繁体   English

与父级具有一对多关系的NHibernate组件

[英]NHibernate component with a one-to-many relation from parent

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, ie 在Job表中,Queue表有一个外键列QueueId,即

Queue.Id <-- Job.QueueId Queue.Id <-Job.QueueId

Using Fluent NHibernate it is pretty straightforward to map this to a property in the Queue class, ie 使用Fluent NHibernate,将其映射到Queue类中的属性非常简单,即

/* 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, ie 然后我需要使用一个组件来映射它,即

/* 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... 关于我在做什么错的任何想法...

Solved. 解决了。 This was caused by a mapping problem in the JobMap. 这是由JobMap中的映射问题引起的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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