Duplicate alias QueryException thrown when executing a modified linq query

Description

I was running into a situation where I was performing a modification to an existing linq query before executing it. The below test code displays what I was trying to accomplish:

--------------------------- IQueryable<Customer> q = from c in db.Customers
from o in c.Orders.Cast<Order>()
where o.ShipCity == "London"
select c;

var q2 = from c in q
from o in c.Orders.Cast<Order>()
select new
{
c.Fax,
o.OrderDate
};

var results = q2.ToList();
---------------------------
I tracked the problem down to the SelectManyVisitor which was executing a CreateCriteria regardless of if the SubCriteria already exists by an alias. The attached patch verifies that no SubCriteria already exist in the root criteria before creating it.

An additional issue that I'm not sure is addressable is if the alias to Orders in the second query were to change (say from o to o2). An exception will then be thrown due to the criteria having a duplicate association path.

Environment

None

Attachments

1

Activity

Show:

Chris Haines 
May 12, 2010 at 1:34 AM

I would appreciate a fix for this, it's creating horrible problems for me trying to build up a fairly simple linq query.

Chad Lee 
October 29, 2009 at 1:13 PM

Can you please provide a test case that verifies the issue is fixed with the patch?

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created September 2, 2009 at 2:34 PM
Updated May 12, 2010 at 1:34 AM
Who's Looking?