Uploaded image for project: 'NHibernate [Moved to GitHub]'
  1. NH-3009

Linq trying to add parameters twice if same predicate is used in query more then once

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 3.2.0.GA
    • Fix Version/s: 3.3.0.CR1
    • Component/s: Linq Provider
    • Labels:
      None
    • Sprint:

      Description

      Expression<Func<Timesheet, bool>> predicate = timesheet => timesheet.Entries.Any(e => e.Id != 1);

      var query = db.Timesheets
      .Where(predicate)
      .Where(predicate) // don't ask why I need this
      .ToList();

      This query throws exception

      System.ArgumentException : An item with the same key has already been added.
      at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
      at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
      at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
      at NHibernate.Linq.Visitors.ExpressionParameterVisitor.VisitConstantExpression(ConstantExpression expression) in ExpressionParameterVisitor.cs: line 43
      ...
      at NHibernate.Linq.Visitors.ExpressionParameterVisitor.Visit(Expression expression) in ExpressionParameterVisitor.cs: line 21
      at NHibernate.Linq.NhLinqExpression..ctor(Expression expression) in NhLinqExpression.cs: line 35
      at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, ref IQuery query, ref NhLinqExpression nhQuery) in DefaultQueryProvider.cs: line 67
      at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in DefaultQueryProvider.cs: line 33
      at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in DefaultQueryProvider.cs: line 40
      at Remotion.Linq.QueryableBase`1.GetEnumerator() in c:\build\Remotion\working\Relinq\Core\QueryableBase.cs: line 132
      at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
      at System.Linq.Enumerable.ToList(IEnumerable`1 source)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              hazzik Alexander Zaytsev
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?