concept LINQ in category entity framework

appears as: LINQ, The LINQ, LINQ
Entity Framework Core in Action

This is an excerpt from Manning's book Entity Framework Core in Action.

EF Core uses Microsoft’s .NET’s Language Integrated Query (LINQ) to carry the commands it wants done, and normal .NET classes to hold the data. Listing 1.2 includes minimal use of LINQ, but later in the book you’ll see much more complex examples.

Listing 5.3 The Index action in the HomeController displays the list of books
public class HomeController : Controller
{
    private readonly EfCoreContext _context;
    public HomeController(EfCoreContext context)  #1  
    {    #1  
        _context = context;    #1  
    }    #1  
    public IActionResult Index    #2  
        (SortFilterPageOptions options)    #3  
    {
        var listService =    #4  
            new ListBooksService(_context);    #4  
        var bookList = listService    #5  
            .SortFilterPage(options)  #5  
            .ToList();  #6  
        return View(new BookListCombinedDto  #7  
            (options, bookList));    #7  
    }

#1   The application’s DbContext is provided by ASP.NET Core via DI.
#2   ASP.NET action, called when the homepage is called up by the user
#3   The options parameter is filled with sort, filter, page options via the URL.
#4   ListBooksService is created using the application’s DbContext from the private field _context.
#5   The SortFilterPage method is called with the sort, filter, page options provided.
#6   The ToList() method executes the LINQ commands, which causes EF Core to translate the LINQ into the appropriate SQL to access the database and return the result as a list.
#7   Sends the options (to fill in the controls at the top of the page) and the list of BookListDtos to display as an HTML table
Entity Framework 4 in Action

This is an excerpt from Manning's book Entity Framework 4 in Action.

LINQ to Entities is the LINQ dialect that enables typed queries against the model. Thanks to the LINQ syntax, you can write a typed query against the model and have an object returned with compile-time checking.

Even though LINQ to Entities operates on objects, it must still be translated into the SQL that’s finally launched against the database. Many of the LINQ methods or overloads can’t be represented in SQL. For instance, the ElementAt method isn’t supported but is still syntactically valid. A call to this method won’t cause a compile-time error but will produce a NotSupportedException at runtime. Similarly, the overload of the Where method that accepts an integer as the second parameter can’t be translated to SQL, so its use causes only a runtime exception. Apart from unsupported methods, you’ll encounter other cases where the compile-time checking isn’t enough, but they’re pretty rare and are well documented in MSDN.

One of the most important features of Entity Framework is the LINQ to Entities query dialect. LINQ to Entities is a specialized version of LINQ that operates on Entity Framework models. LINQ to Entities isn’t a LINQ to SQL competitor—it’s the Entity Framework’s main query language, whereas LINQ to SQL is a full-featured O/RM that shipped with the .NET Framework v3.5.

In this chapter, we’ll begin by looking at how to filter data. Then we’ll cover projecting, grouping, sorting, joining, and querying within inheritance hierarchies. With this approach, you’ll gradually learn how LINQ to Entities works and understand how to obtain the same data you would get using native SQL queries. We’ll assume that you’re already familiar with LINQ. If you haven’t seen it yet, you can read appendix A to learn the basics.

What is the future of LINQ to SQL?
Listing 9.7. Chaining query-builder methods vs. chaining LINQ to Entities methods