subsonic / SubSonic-3.0

SubSonic 3.0 for the .NET 3.5 Framework
http://subsonic.github.io/
558 stars 210 forks source link

LINQ -Incorrect field naming with mulitple joins w/ tables with same fieldnames #213

Open awbacker opened 14 years ago

awbacker commented 14 years ago

I have 3 tables that I am joining in LINQ, and selecting records from the 3rd. Because I am doing joins, tables 2 & 3 have the same column name at least once (the fk-pk link). What happens is that because I am 'selecting' table 3, the column I need is renamed to MyPK1, and so the object is never correctly populated.

This can be solved by using table_field naming standards, t0_field, t1_field, etc and tracking where the data goes.

from x in Data.TableX.All()
join y in Data.TableY.All() on x.x_pk equals y.x_pk
join z in Data.TableZ.All() on y.MyPK = z.MyPK
select z;

This gives me sql like this, where MyPK1 will not go into the property MyPK, for obvious reasons. select ...., [t2].MyPK as MyPK1, [t2].FieldA, [t2].FieldB, ... FROM ...

saintedlama commented 14 years ago

Could you specify what's behind Data.TableX? Are you using SimpleRepo, ActiveRecord or plain Query objects?