static void Main(string[] args)
{
using (DBEntities ef = new DBEntities())
{
//========ef查询==============
var l = from a in ef.aa
where a.Id == 35
select a;
foreach (var i in l)
{
Console.WriteLine("id:{0},name:{1}", i.Id, i.name);
}
//========ef添加==============
var j = new aa
{
name = "测试ok!"
};
ef.aa.AddObject(j);
int num = ef.SaveChanges();
Console.WriteLine("受影响的行数为 {0}", num);
//========ef删除==============
var jj = ef.aa.Single(xx => xx.Id == 38);
ef.aa.Attach(jj);
ef.aa.DeleteObject(jj);
ef.SaveChanges();
//========ef修改==============
var result = ef.aa.Single(x => x.name == "bbs");
result.name = "hhhhhhhhhhhhhhhhh";
ef.SaveChanges();
}
}
EF增删改查
最新推荐文章于 2024-06-16 22:54:26 发布