Just sharing some of my inconsequential lunch conversations with you... RSS  

Monday, October 20, 2008

LINQ to SQL Bug?

Here a great little LINQ to SQL bug. Consider the following code:

    IEnumerable<MasterEntity> masters = db.ExecuteQuery<MasterEntity>(
@"select * from MasterEntity master join DetailEntity detail on master.id = detail.MasterId
);



Not imagine if you have the same name column both on MasterEntity and DetailEntity, let's say 'IsMandatory'. When you try and get a this property form a MasterEntity object, what should you get?




  1. MasterEntity.Name?


  2. An exception, as Name can be ambiguous?



Well, on my code it happen to return... DetailEntity.Name! Yes, on my dev box the implementation seems to return the first projection by name. If you really want MasterEntity.Name to get returned, you'll have to get:



    IEnumerable<MasterEntity> masters = db.ExecuteQuery<MasterEntity>(
@"select master.* from MasterEntity master join DetailEntity detail on master.id = detail.MasterId
);


Funny, right? I'd expect MasterEntity.Name to get returned, as your asking for a MasterEntity object, right? No ambiguousness here, or am I wrong?

No comments:

Development Catharsis :: Copyright 2006 Mário Romano