使用EF进行最基本的增删改查,直接贴代码。
static void Main(string[] args)
{
PeopleEntities context = new PeopleEntities();
//增
//context.Student.Add(new Student() { Name = "heyuke", Age = 18 });
//context.SaveChanges();
//Console.WriteLine("ok");
//Console.ReadLine();
//删
//var result = from s in context.Student
// where s.Id==4
// select s;
//context.Student.Remove(result.FirstOrDefault());
//context.SaveChanges();
//改
var result = from s in context.Student
where s.Id == 1
select s;
Student s1 = result.FirstOrDefault();
s1.Name = "heyuke";
context.SaveChanges();
//查
// context.Student.Select(s => s);
//linq to sql
//var result = from s in context.Student
// select s;
//Console.WriteLine(result.Count());
//Console.ReadLine();
}