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?
- MasterEntity.Name?
- 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:
Post a Comment