Database Reference
In-Depth Information
static void RunExample()
{
using (var context = new EFRecipesEntities())
{
context.Employees.Add(new Employee
{
FirstName = "Jill",
LastName = "Robins",
BirthDate = DateTime.Parse("3/2/1976")
});
context.Employees.Add(new Employee
{
FirstName = "Michael",
LastName = "Kirk",
BirthDate = DateTime.Parse("4/12/1985")
});
context.Employees.Add(new Employee
{
FirstName = "Karen",
LastName = "Stanford",
BirthDate = DateTime.Parse("7/6/1963")
});
context.SaveChanges();
}
using (var context = new EFRecipesEntities())
{
Console.WriteLine("Query using eSQL");
var esql = @"Select EFRecipesModel.FullName(e) as Name,
EFRecipesModel.Age(e) as Age from
EFRecipesEntities.Employees as e";
var objectContext = (context as IObjectContextAdapter).ObjectContext;
var emps = objectContext.CreateQuery<DbDataRecord>(esql);
foreach (var emp in emps)
{
Console.WriteLine("Employee: {0}, Age: {1}", emp["Name"],
emp["Age"]);
}
}
using (var context = new EFRecipesEntities())
{
Console.WriteLine("\nQuery using LINQ");
var emps = from e in context.Employees
select new
{
Name = MyFunctions.FullName(e),
Age = MyFunctions.Age(e)
};
Search WWH ::




Custom Search