score:3

Accepted answer

There seems to be a bug here.

Your query desugars to:

IQueryable<IStudentTermData> query =
    studentTermDataSet.Join(studentSet,
                            studentTermData => studentTermData.StudentId,
                            student => student.Id,
                            (studentTermData, student) => new {studentTermData, student})
                      .Where(s => (s.student.Active))
                      .Select(std => std.studentTermData);

The only parameter called "constructor" is the last parameter of the Join method, and indeed, if you change the code to:

var query =
    studentTermDataSet.Join(studentSet,
                            studentTermData => studentTermData.StudentId,
                            student => student.Id,
                            Tuple.Create);

then it compiles without warnings.

The difference is that the first query uses the Join overload which takes an Expression as a parameter, whereas the second one takes a Func (and returns an IEnumerable).

So I think that the support for expression trees is possibly not complete yet. You could post a question on the Code Contracts forum to ask about this.


Related Articles