【发布时间】:2014-04-11 18:13:42
【问题描述】:
两个表:
CREATE TABLE [dbo].[Error](
[ErrorId] [int] IDENTITY(1,1) NOT NULL,
[ResponseId] [int] NOT NULL,
<Other fields>
CONSTRAINT [PK_Error] PRIMARY KEY CLUSTERED
(
[ErrorId] ASC
)
CREATE TABLE [dbo].[Response](
[ResponseId] [int] IDENTITY(1,1) NOT NULL,
<other fields>
CONSTRAINT [PK_Response] PRIMARY KEY CLUSTERED
(
[ResponseId] ASC
)
还有课程
public partial class ErrorType
{
public virtual long Id { get; set; }
public virtual hr_information_type Response { get; set; }
<other fields>
}
public class hr_information_type
{
public virtual long Id { get; set; }
public virtual ErrorType[] Errors { get; set;}
<other fields>
}
我正在使用自动映射,并因此覆盖它:
public class hr_information_typeMap : IAutoMappingOverride<hr_information_type>
{
public void Override(AutoMapping<hr_information_type> mapping)
{
mapping.Table("Response");
mapping.Id(x => x.Id).Column("ResponseId");
mapping.HasMany(many => many.Errors).AsArray(a => a.Response, x => x.Column("ResponseId"));
}
}
public class ErrorTypeMap : IAutoMappingOverride<ErrorType>
{
public void Override(AutoMapping<ErrorType> mapping)
{
mapping.Table("Error");
mapping.Id(id => id.Id).Column("ErrorId");
mapping.References(r => r.Response, "ResponseId");
}
}
我遇到的问题是,当我调用 Session.Load(id) 时,出现以下错误
"无法初始化集合:" 有内部异常 "无效的列名 'hr_information_type_id'"
因为它生成的 SQL 为
SELECT
errors0_.hr_information_type_id as hr7_1_,
errors0_.ErrorId as ErrorId1_,
errors0_.ResponseId as ResponseId1_,
errors0_.ErrorId as ErrorId26_0_,
errors0_.ResponseId as ResponseId26_0_
FROM Error errors0_
WHERE errors0_.hr_information_type_id=?
我不知道它为什么要查找我从未说过存在的列,也不知道它为什么要查找任何列两次。
我做错了什么?我在其他不使用自动映射的项目中有非常相似的代码,所以这不是进行覆盖的正确方法吗?
【问题讨论】:
标签: c# sql nhibernate fluent-nhibernate automapping