Database Reference
In-Depth Information
Listing 6-26. Inserting into and Retrieving from Our Model
using (var context = new EF6RecipesContext())
{
Context.Database.ExecuteSqlCommand(@"insert into chapter6.toy
(Name,ForDonationOnly) values ('RagDoll',1)");
var toy = new Toy { Name = "Fuzzy Bear", Price = 9.97M };
var refurb = new RefurbishedToy { Name = "Derby Car", Price = 19.99M,
Quality = "Ok to sell" };
context.Toys.Add(toy);
context.Toys.Add(refurb);
context.SaveChanges();
}
using (var context = new EF6RecipesContext())
{
Console.WriteLine("All Toys");
Console.WriteLine("========");
foreach (var toy in context.Toys)
{
Console.WriteLine("{0}", toy.Name);
}
Console.WriteLine("\nRefurbished Toys");
foreach (var toy in context.Toys.OfType<RefurbishedToy>())
{
Console.WriteLine("{0}, Price = {1}, Quality = {2}", toy.Name,
toy.Price, ((RefurbishedToy)toy).Quality);
}
}
The following is the output from Listing 6-26:
All Toys
========
Fuzzy Bear
Derby Car
Refurbished Toys
Derby Car, Price = 19.99, Quality = Ok to sell
6-10. Creating a Filter on Multiple Criteria
Problem
You want to filter rows for an entity based on multiple criteria.
Solution
Let's assume that we have a table that holds web orders, as shown in Figure 6-13 .
 
Search WWH ::




Custom Search