We're updating the issue view to help you get more done. 

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

Status

Assignee

Unassigned

Reporter

John

Labels

None

Components

Affects versions

1.0.0

Priority

Minor