3

Is there somebody that could translate this query to Linq in C# . I was searching and I didn't find any query similiar to. Thanks a lot guys! SQL Sentence:

SELECT a.Amenaza, c.Nombre, c.Descripcion
 FROM AmenazasEstablecer a, ControlesEstablecer c, Matriz_Amenazas_ControlesEstablecer m
 WHERE a.IdAmenaza = m.IdAmenaza AND c.IdControl=m.IdControl;
Femaref
  • 60,705
  • 7
  • 138
  • 176
Antonio
  • 31
  • 1
  • 2

2 Answers2

5

You will have to have a DataContext created and specified, but once you do you could get away with:

MyDataContext context = new MyDataContext("SomeConnectionString");

var results = from a in context.AmenazasEstablecer
              from c in context.ControlesEstablecer
              from m in context.Matriz_Amenazas_ControlesEstablecer
              where a.IdAmenaza == m.IdAmenaza && c.IdControl == m.IdControl
              select new {
                  a.Amenaza,
                  c.Nombre,
                  c.Descripcion
              });
Joel Etherton
  • 37,325
  • 10
  • 89
  • 104
4
var results = from a in context.AmenazasEstablecer 
              join m in context.Matriz_Amenazas_ControlesEstablecer 
                          on  a.IdAmenaza equals m.IdAmenaza
              join c in context.ControlesEstablecer 
                          on c.IdControl equals m.IdControl
             select new {a.Amenaza, c.Nombre, c.Descripcion};
Bala R
  • 107,317
  • 23
  • 199
  • 210
  • @Adrian: I'm in the same boat. I think they're cleaner. I actually started writing this exact code out for my answer but changed it when I realized that OP was asking specifically for a cross join. I upvoted this answer anyway. – Joel Etherton May 26 '11 at 16:59