Database Reference
In-Depth Information
Figure 11-11. An Appointment entity with the start and end times for appointments
If we want to find all of the appointments for Thursday, we can't use the CLR enum DayOfWeek.Thursday to
compare with the StartsAt property in a where clause because this does not translate to a data store statement.
We need to use the pattern shown in Listing 11-18.
Listing 11-18. Using a Database Function in a LINQ Query
class Program
{
static void Main(string[] args)
{
RunExample();
}
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
var app1 = new Appointment
{
StartsAt = DateTime.Parse("7/23/2013 14:00"),
GoesTo = DateTime.Parse("7/23/2013 15:00")
};
var app2 = new Appointment
{
StartsAt = DateTime.Parse("7/24/2013 9:00"),
GoesTo = DateTime.Parse("7/24/2013 11:00")
};
var app3 = new Appointment
{
StartsAt = DateTime.Parse("7/24/2013 13:00"),
GoesTo = DateTime.Parse("7/23/2013 15:00")
};
context.Appointments.Add(app1);
context.Appointments.Add(app2);
context.Appointments.Add(app3);
context.SaveChanges();
}
 
Search WWH ::




Custom Search