两个表:
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=?我不知道为什么它要查找一个我从未说过存在的列,也不知道为什么它要两次查找任何列。
我做错了什么?我在其他不使用Auto Mapping的项目中有非常类似的代码,所以这不是进行覆盖的正确方法吗?
发布于 2014-04-15 03:30:06
Mapping.HasMany( part => many.Errors).AsArray(a => a.Response,part => )
它需要一个索引和一个键。我查看了它生成的HBM文件(使用
.Mappings(m =>
{
m.FluentMappings.AddFromAssembly(assembly).ExportTo(@"C:\nh.out");
m.AutoMappings.Add(am).ExportTo(@"C:\nh.out");
})
看到了这一点。索引是part.Column("ErrorId")部分,这是它对集合进行索引的方式(即使它只是一个数组)。这让我走得更远,但不是100%确定这是完整的答案。
https://stackoverflow.com/questions/23019798
复制相似问题