zoukankan      html  css  js  c++  java
  • linq to entity报"不允许启动新事务,因为有其他线程正在该会话中运行."错误解决方法

    using (var entity = new USERRIGHTEntities())
                    {
                        int tCode = Convert.ToInt32(tPropertiesCode);
                        //var catetory = entity.T_ModelProperties.Where(o => o.F_ProperieCode == int.Parse(tPropertiesCode));
                        var catetory = entity.T_ModelProperties.Where(o => o.F_ProperieCode == tCode);
                        if (catetory.Any())
                        {
                            foreach (var item in catetory)
                            {
                                entity.DeleteObject(item);
                                //entity.SaveChanges();
                            }
                            entity.SaveChanges();
                        }
                    }

    可以把entity.SaveChanges();放到循环外边,就可以成功删除了,也可以成功删除多条数据。

    You can reach me by surfing the web ---- huntjobs.cn,or sending e-mails to me,Here is my qq MailBox:1424870395@qq.com
  • 相关阅读:
    53、Gif 控件GifView 的使用,播放gif图片
    52、图片缩放库 PhotoView
    51、自定义View基础和原理
    Adapter适配器 final int Id 导致选中的Item不在当前界面
    Linux目录结构
    Linux包管理工具分析
    Linux 软件包安装管理
    MySQL配置详解
    MySQL 5.5.x配置文件详解
    Linux Apache2 配置介绍
  • 原文地址:https://www.cnblogs.com/HedgehogBlog/p/3466976.html
Copyright © 2011-2022 走看看