排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:50010702506256
欢迎加群交流技术
分类:
Csharp
方法一直接查询SQL语句
//实例表格 oaEntities oaentities = new oaEntities(); //使用SQL语句(不常用) int count = oaentities.Database.ExecuteSqlCommand("delete from UserInfo where sid=@userid", new SqlParameter("userid", userid));
方法二先查询,在删除
//实例表格 oaEntities oaentities = new oaEntities(); UserInfo userdatatable = oaentities.UserInfo.Where(a => a.sid == (int)usersid).FirstOrDefault(); if (userdatatable==null) { return Content("没有该数据"); } //修改状态 oaentities.UserInfo.Remove(userdatatable); //把修改提交到数据库(返回受影响行数) int row = oaentities.SaveChanges();
方法三直接删,不用查询,效率最快
//实例表格 oaEntities oaentities = new oaEntities(); UserInfo userinfotable = new UserInfo() { sid = (int)usersid }; //修改的状态 oaentities.Entry(userinfotable).State = System.Data.EntityState.Deleted; //把修改后提交到数据库(返回受影响行数) oaentities.SaveChanges();
评价