Two tables:
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
)
And the classes
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>
}
I'm using Auto mapping, and overriding it thusly:
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");
}
}
The problem I have is, when I call Session.Load(id), I get the following error
"could not initialize a collection: " with an Inner Exception "Invalid column name 'hr_information_type_id'"
because it generates the SQL as
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=?
I have no idea why it's looking for a column I never said was there, nor why it's looking for any columns twice.
What am I doing wrong? I have very similar code in other projects that are not using Auto Mapping, so is this not the correct way to do the override?