我有一个奇怪的问题:每当我查询具有 IList 的实体时,它仍然是空的。可以查询语言实体本身...这与我的复合键有关吗?
NHProf 显示 BOTH 实体都被 sql 查询,但由于某种原因,结果没有链接:-/
这是一些代码:
public class Employee : User
{
public virtual string firstname { get; set; }
public virtual string lastname { get; set; }
public virtual string uid { get; set; }
public virtual string identity_provider
public virtual IList<Language> languages { get; set; }
}
对应的映射:
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
Table("employee");
Not.LazyLoad();
CompositeId()
.KeyProperty(x => x.uid)
.KeyProperty(x => x.identity_provider);
Map(x => x.firstname);
Map(x => x.lastname);
HasMany<Language>(x => x.languages)
.Table("employee_spoken_language")
.KeyColumns.Add("employee_uid","employee_identity_provider")
.Inverse().Cascade.All();
}
}
为了完整起见,这就是“语言”的映射方式:
public class LanguageMap : ClassMap<SpokenLanguage>
{
public LanguageMap()
{
Table("employee_spoken_language");
Not.LazyLoad();
CompositeId()
.KeyProperty(x => x.employee_uid)
.KeyProperty(x => x.employee_identity_provider)
.KeyProperty(x => x.name);
References(x => x.knowledge_level).Column("knowledge_level");
}
}
无论我改变什么,我的员工实体总是显示language = {}
!?这真的让我发疯,我找不到错误。我确保执行查询语言的 sql!我确保数据在数据库中。而且因为我使用的是fluent,我还检查了创建的hmb:
<bag cascade="all" inverse="true" name="languages" table="employee_spoken_language">
<key>
<column name="employee_uid" />
<column name="employee_identity_provider" />
</key>
<one-to-many class="Jobportal.Language, wcf, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bag>
希望有人可以对此有所了解...在此先感谢!
问候,马丁