日期:2014-05-20 浏览次数:20780 次
private static void QueryContactsUseEntitySQL()
{
using (var context = new SampleEntities())
{
var queryString = "SELECT VALUE c " +
"FROM SampleEntities.Contacts AS c " +
"WHERE c.FirstName='Robert'";
ObjectQuery<Contact> contacts = context.CreateQuery<Contact>(queryString);
foreach (var contact in contacts)
{
Console.WriteLine("{0} {1}", contact.FirstName.Trim(), contact.LastName);
}
}
Console.Write("Press Enter...");
Console.ReadLine();
}
namespace Chapter2ConsoleApp
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class SampleEntities : DbContext
{
public SampleEntities()
: base("name=SampleEntities")
{
}