Database Reference
In-Depth Information
context.Events.Add(ev3);
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
Console.WriteLine("Events with Platinum Sponsors");
Console.WriteLine("=============================");
var esql = @"select value e from EFRecipesEntities.Events as e where
ref(e.Sponsor) in (EFRecipesModel.PlatinumSponsors())";
var objectContext = (context as IObjectContextAdapter).ObjectContext;
var events = objectContext.CreateQuery<Event>(esql);
foreach (var ev in events)
{
Console.WriteLine(ev.Name);
}
}
}
}
The output of the code in Listing 11-14 is as follows:
Events with Platinum Sponsors
=============================
Concerts in the Park
11th Street Art Festival
How It Works
The <ReferenceType> element in the conceptual model denotes a reference to an entity type. This means that we are
returning a reference to an entity, not the complete entity. Our model-defined function returns a collection of references
to Platinum-level sponsors. To illustrate using our function, we created an eSQL expression in Listing 11-14 to get all
of the events with Platinum-level sponsors. There are, of course, lots of different ways to get the events sponsored by
Platinum-level sponsors, but by encapsulating the collection of Platinum-level sponsors in our model-defined function,
we introduce a bit of code reusability.
We didn't show a corresponding use in a LINQ query because the bootstrapping code would need to return an
IQueryable<EntityKey> , which is fine, but a subsequent Contains clause would not work because the result is not
strongly typed.
11-8. Using Canonical Functions in eSQL
Problem
You want to call a canonical function in your eSQL query. A canonical function is an eSQL function that is natively
supported by all data providers. Examples include Sum() , Count() , and Avg() .
 
Search WWH ::




Custom Search