Database Reference
In-Depth Information
var associate = await context.Associates.
Include(x => x.AssociateSalaries).
OrderBy(x => x.Name).
FirstOrDefaultAsync(y => y.Name == "Kevin Hodges");
Console.WriteLine("Here are the salaries for Associate {0}:", associate.Name);
foreach (var salaryInfo in associate.AssociateSalaries)
{
Console.WriteLine("\t{0}", salaryInfo.Salary);
}
await Task.Delay(5000);
}
}
Listing 3-3 outputs the following result:
Cleaning Up Previous Test Data
=========
Adding Test Data
=========
Async ForEach Call
=========
Here are the salaries for Associate Janis Roberts:
39500.00
Here are the salaries for Associate Kevin Hodges:
41900.00
Here are the salaries for Associate Bill Jordan:
33500.00
Async ToList Call
=========
Here are the salaries for Associate Bill Jordan:
33500.00
Here are the salaries for Associate Janis Roberts:
39500.00
Here are the salaries for Associate Kevin Hodges:
41900.00
Async SingleOrDefault Call
=========
Here are the salaries for Associate Kevin Hodges:
41900.00
How It Works
In this example, we demonstrate two key concepts of Entity Framework usage: Querying the model using the LINQ
extensions for Entity Framework and the new asynchronous capabilities implemented in Entity Framework 6.
For the vast majority of your query operations, you want to use LINQ. Doing so will give you IntelliSense ,
compile-time checking, and a great strongly typed experience. If you have a use case that requires the construction
of a dynamic query at runtime, you may consider using Entity SQL, which enables you to concatenate strings for
various parts of the query expression. You will find Entity SQL examples contained in the recipes in this chapter.
 
Search WWH ::




Custom Search