Paymentsense / Dapper.SimpleLoad

Dapper.SimpleLoad
MIT License
13 stars 4 forks source link

If Table and Primary Key and on a Parent Class the child fails to load in a many to one relation ship #5

Closed oliverreid closed 8 years ago

oliverreid commented 8 years ago
[Table("tableName")]
public class A
{
    [PrimaryKey]
    public int key {get; set;}
}
public class B : A
{
}
public class C
{
    [Column("MerchantGuid")]
    [ManyToOne]
    public B Bobject { get; set; }
}

Boject is not loaded when autoQuerying class C

bartread commented 8 years ago

I can't reproduce this. I'm wondering if it might be a decoration issue, because if I use the following definitions it works fine:

        [Table("[test].[A]")]
        public class A
        {
            [PrimaryKey]
            public int AKey {get; set;}
        }

        public class B : A
        {
        }

        [Table("[test].[C]")]
        public class C
        {
            [PrimaryKey]
            public int? CKey { get; set; }

            [Column("BKey")]
            [ManyToOne]
            public B Bobject { get; set; }
        }

Against these DAOs the following query:

var results = connection.AutoQuery<C, B>(new { CKey = 1 });

Generates this SQL:

SELECT [ta0_c].[CKey], 
    [ta1_b].[AKey]
FROM [test].[C] AS ta0_c
LEFT OUTER JOIN [test].[A] AS ta1_b
    ON ta1_b.[AKey] = ta0_c.[BKey]
WHERE ta0_c.[CKey] = @CKey
;

The SplitOn property contains an array with a single element, "AKey", which is what I'd expect to see, based on the DAO definitions.

bartread commented 8 years ago

Closing for now but will reopen if we find a scenario where it's still live.