标签:
(IObjectContextAdapter)this).ObjectContext.ExecuteFunction("sp_alterdiagram", diagramnameParameter, owner_idParameter, versionParameter, definitionParameter);
}
///<summary>
/// 使用EF的ORM框架来对数据库进行增删改查
///
/// </summary>
SQLtestEntities sqlentity = new SQLtestEntities();
//增加行
Eftest eft1 = new Eftest() { ID = 3, name = "spike", password = "123", ds = "xiaolizi" };
sqlentity.Eftest.Add(eft1);
sqlentity.SaveChanges();
//查找行
var cc = sqlentity.Eftest.Select(s => s).Where(s => s.name == "spike");
foreach (var item in cc)
{
Console.WriteLine(item.ID + " " + item.name + " " + item.password + " " + item.ds);
}
sqlentity.SaveChanges();
//删除行
var eft4 = sqlentity.Eftest.Where(s => s.ID == 2).Select(s => s);
sqlentity.Eftest.Remove(eft4.FirstOrDefault());
var eft5 = sqlentity.Eftest.Where(s => s.name == "spike").Select(s => s);
sqlentity.Eftest.RemoveRange(eft5);
sqlentity.SaveChanges();
//更改行
var eft6 = sqlentity.Eftest.Where(s => s.name == "spike").Select(s => s);
Eftest eft7 = (Eftest)eft6.FirstOrDefault();
// eft7.ID = 10; // 这句是错误的,KEY的值不能修改,这就话搞不明白为什么
eft7.name = "spike";
eft7.password = "ji11";
eft7.ds = "this is a test for you ,my lover!";
sqlentity.SaveChanges();
Console.ReadKey();
标签:
原文地址:http://www.cnblogs.com/weloveshare/p/5326070.html