views:

225

answers:

0

I am trying to retrieve the individual detail rows without having to create an object for the parent. I have a map which joins a parent table with the detail to achieve this:

Table("UdfTemplate");
Id(x => x.Id, "Template_Id");
Map(x => x.FieldCode, "Field_Code");
Map(x => x.ClientId, "Client_Id");

Join("UdfFields", join =>
{
    join.KeyColumn("Template_Id");

    join.Map(x => x.Name, "COLUMN_NAME");
    join.Map(x => x.Label, "DISPLAY_NAME");
    join.Map(x => x.IsRequired, "MANDATORY_FLAG")
        .CustomType<YesNoType>();
    join.Map(x => x.MaxLength, "DATA_LENGTH");
    join.Map(x => x.Scale, "DATA_SCALE");
    join.Map(x => x.Precision, "DATA_PRECISION");

    join.Map(x => x.MinValue, "MIN_VALUE");
    join.Map(x => x.MaxValue, "MAX_VALUE");
});

When I run the query in NH using:

Session.CreateCriteria(typeof(UserDefinedField))
    .Add(Restrictions.Eq("FieldCode", code)).List<UserDefinedField>();

I get back the first row three times as opposed to the three individual rows it should return. Looking at the SQL trace in NH Profiler the query appears to be correct. The problem feels like it is in the mapping but I am unsure how to troubleshoot that process. I am about to turn on logging to see what I can find but I thought I would post here in case someone with experience mapping joins knows where I am going wrong.

related questions