Querying for filtered items

Let's say we have the following code:

using System.Linq;

using
(var db = new GameDbContext())
{
var users = db.Users
.Where(u => u.GamesPlayed > 5
)
.OrderBy(u => u.FirstName)
.ToList();
}

In the preceding code, we are trying to hypothetically return all the users who have played more than 5 games in total using LINQ. You can also use any other methods and properties that are available in LINQ, including GroupBy, OrderByDescending, and others. LINQ is a very powerful library on its own, and it is recommended that you should be familiar with it. If you are a total beginner to LINQ, it may help you to go through the basics here: https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/basic-linq-query-operations.

You will find that a tool called LINQPad, especially version 6, which can be found at https://www.linqpad.net/LINQPad6.aspx, is a great resource for working with LINQ in .NET Core 3.

In more complex scenarios, you may have multiple queries all operating together for one purpose, and in these situations, it may be desirable that, if one query out of the group fails, then all the others should be rolled back. This is when transactions come into play. We will look at transactions in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.239.103