Plans to add BelongToAttribute support in SQL Expression?

We noticed that the BelongToAttribute used to be supported in the JoinBuilder, but in the move to the SQL Expression class, the attribute is not processed anymore.

There are cases where the auto naming conventions don’t quite fit, and the BelongToAttribute could come to the rescue!

Right the [BelongTo] was only used in JoinSqlBuilder, do you have an example of how you want it to work using SqlExpression?

standby - will post something tomorrow. awesome response time!

Let’s say we have 3 classes corresponding to tables:

class A
{
    int Id { get; set; }
    string SomeAProperty { get; set; }
}
class B
{
   int Id { get; set; }
   string SomeBProperty { get; set; }

   [ForeignKey(typeof(A))]
   int AId { get; set; }
}

class C
{
   int Id { get; set; }
   string SomeCProperty { get; set; }

   [ForeignKey(typeof(B))]
   int BId { get; set; }
}

and we want to select A InnerJoin B LeftJoin(B, C) into a fourth class:

class D
{
    int Id { get; set; }

   [BelongTo(typeof(B))]
   int BId { get; set; }

   int CId { get; set; }

   string SomeAProperty { get; set; }
   string SomeBProperty { get; set; }
   string SomeCProperty { get; set; }
}

With the current implementation where BelongTo is ignored, the SELECT clause tries to retrieve the BId property from the C.BId column (instead of B.Id column) which can be null because of the LeftJoin. The BelongTo could be used as in D class to disambiguate and give precedence to the B table over the C table in the column resolving logic.

As a side note, the ambiguous column being the key for a left join in this particular case, B.Id could (arguably) have been a better default match even without a BelongTo attribute. But I can see how translating that kind of rule in code would be way more tricky than the actual lookup rules…

Ok this should now be implemented from this commit.

This change is available from v4.0.55 that’s now available on MyGet.

the code change looks like it will do the trick - will get around to testing it soon.