Uploaded image for project: 'NHibernate.Linq [DEPRECATED]'
  1. NHLQ-43

Duplicate alias QueryException thrown when executing a modified linq query

    Details

    • Type: Patch
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.0.0
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              jweber jweber
            • Votes:
              2 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:

                Who's Looking?