Database Reference
In-Depth Information
context.Associates.Add(john);
context.Associates.Add(steve);
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
Console.WriteLine("Using eSQL...");
var emps = context.Associates.OfType<TeamMember>()
.Where(@"EFRecipesModel.GetProjectManager(it).Name =
@projectManager ||
EFRecipesModel.GetSupervisor(it).Name == @supervisor",
new ObjectParameter("projectManager", "Jill Masterson"),
new ObjectParameter("supervisor", "Steve Johnson"));
Console.WriteLine("Team members that report up to either");
Console.WriteLine("Project Manager Jill Masterson ");
Console.WriteLine("or Supervisor Steve Johnson");
foreach (var emp in emps)
{
Console.WriteLine("\tAssociate: {0}", emp.Name);
}
}
using (var context = new EFRecipesEntities())
{
Console.WriteLine();
Console.WriteLine("Using LINQ...");
var emps = from e in context.Associates.OfType<TeamMember>()
where MyFunctions.GetProjectManager(e).Name ==
"Jill Masterson" ||
MyFunctions.GetSupervisor(e).Name == "Steve Johnson"
select e;
Console.WriteLine("Team members that report up to either");
Console.WriteLine("Project Manager Jill Masterson ");
Console.WriteLine("or Supervisor Steve Johnson");
foreach (var emp in emps)
{
Console.WriteLine("\tAssociate: {0}", emp.Name);
}
}
}
}
public class MyFunctions
{
[EdmFunction("EFRecipesModel", "GetProjectManager")]
public static ProjectManager GetProjectManager(TeamMember member)
{
throw new NotSupportedException("Direct calls not supported.");
}
 
Search WWH ::




Custom Search