0

It's a simple difficult that I need help. I have a linq expression on C# that I'm trying to do but I don't know how to do that.

In this expression I just need to add an "AND" or "&&" like the code below.

on comentListaDef.Id equals respostaComentListaDef.IdComentListaDef &&   
RespostaComentListaDef.IdAutor = 1072  
Victor
  • 724
  • 3
  • 12
  • 32

3 Answers3

1

You should be applying that condition in a where before (or after) the join, not in the actual join expression, given that you're filtering out items from one of the sets, rather than determining which items are or are not a match between the two sets.

Servy
  • 202,030
  • 26
  • 332
  • 449
0

You should use anonymous objects to perform JOIN with multiple join conditions:

join respostaComentListaDef in db.RespostaComentListaDef
on new { Id = comentListaDef.Id, IdAutor = 1072 } equals new { Id =  respostaComentListaDef.IdComentListaDef, respostaComentListaDef.IdAutor }
MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
0

You need to join by two anonymous objects with the same property names

join respostaComentListaDef in db.RespostaComentListaDef
on new { comentListaDef.Id, IdAutor = 1072 } equals 
   new { Id = respostaComentListaDef.IdComentListaDef, respostaComentListaDef.IdAutor }
Aducci
  • 26,101
  • 8
  • 63
  • 67
  • very good! worked fine! like i said to @MarcinJuraszek, i had to create a new class to understand the anonymous type :) – Victor Jul 13 '15 at 17:44