日期:2014-05-17  浏览次数:21785 次

EF并发问题,在提供程序连接上启动事务时出错。有关详细信息,请参阅内部异常。

      Entities data=new Entities();

            var list = from p in data.Record
                        where p.CreateTime >= d && p.CreateTime < DateTime.Today
                        select new
                        {
                            ID = p.ID,
                            Name = p.Name,
                            UserID=p.UserID
                        };


            foreach (var item in list)
            {
                var record = data.Record.FirstOrDefault(a => a.ID == item.ID);
                 if (record != null)
                 {
                     record.RankTime = record.CreateTime.AddDays(3);
                     data.SaveChanges();


                     BusinessModel.KeywordRank mod = new KeywordRank();
                     mod.RecordID = item.ID;
                     mod.UserID = item.UserID;
                     mod.Name = item.Name;
                     mod.Rank = 0;
                     mod.CreateTime = DateTime.Now;

                     data.KeywordRank.Add(mod);
                     data.SaveChanges(); &nbs