使用DbSet的Local属性可以访问当前context中被追踪且没有被标记为删除的实体(内存中的数据) using (var context = new BloggingContext()) { // Load all blogs from the database into the context context.Blogs.Load(); // Add a new blog to the context context.Blogs.Add(new Blog { Name = "My New…
using (var db = new Entities()) { //数据操作 } 新增 string sql = "insert into UserInfo values('zhangsan','123456')"; db.Database.ExecuteSqlCommand(sql); 参数化新增 sql = "insert into UserInfo values(@UserName,@UserPass)"; var param = new SqlParam…
某天 , 在review项目中代码的时候, 发现有哥们直接通过 Database.ExecuteSqlCommand("select * from order_info where company like '%abc%' ")的方式与数据库查询, 私下问其是否知道这个方法还有一个带有params object[] parameters参数重载, 对方爽快的回答:"知道啊 ,只是每次都要写一大堆的SqlParameter[] 定义, 实在是太过麻烦了,特别是有的时候查询参数…