More complex queries in LINQ than SQL

I am new to LINQ queries. I have read / researched all the benefits of LINQ SQL queries, but I have one main question, why do we need to use these queries because I feel that their syntax is more complex than traditional sql queries?

For example, see the example below for a simple left external connection.

    var q=(from pd in dataContext.tblProducts 
           join od in dataContext.tblOrders on pd.ProductID equals od.ProductID into t 
           from rt in t.DefaultIfEmpty() 
           orderby pd.ProductID 
           select new 
           { 
               //To handle null values do type casting as int?(NULL int)
               //since OrderID is defined NOT NULL in tblOrders
               OrderID=(int?)rt.OrderID,
               pd.ProductID,
               pd.Name,
               pd.UnitPrice,
               //no need to check for null since it is defined NULL in database
               rt.Quantity,
               rt.Price,
           })
           .ToList(); 
+4
source share
3 answers

Thus, the LINQ (Language Integrated Queries) point is an easy way to work with enumerated collections when running memory. Contrast with SQL, which is the language for determining what a user retrieves from a dataset in a database.

- , SQL, LINQ- SQL , "" - . SQL ; LINQ - " ", foreach.

, :

foreach(Thing thing in things)
{
    if(thing.SomeProperty() == "Some Value")
        return true;
}

... LINQ:

return things.Any(t => t.SomeProperty() == "Some Value");

, , IL-. , .

LINQ; foreach, , , . , - - LINQ- foreach , , foreach?

"", foreach.

+2

sql linq, .

linq - , , , .

, . . , .

< >

  • -

  • .
  • ,
  • sql , .
  • DBML concurrency

, , Sql, , LINQ. Sql, , linq.

+1

, LINQ, , -, SQL-, LINQ. LINQ, LINQ . , LINQ . / . , .

+1
source

Source: https://habr.com/ru/post/1536102/


All Articles