Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL to LINQ in C# (query with several tables and alias)

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;
like image 293
Antonio Avatar asked Dec 08 '25 20:12

Antonio


1 Answers

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
              });
like image 64
Joel Etherton Avatar answered Dec 11 '25 10:12

Joel Etherton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!