MVC3 LINQ SubmitChanges 无效
在下面的方法中,db.SubmitChanges 显示为无效/无法被智能感知识别。 这是我第一次尝试使用 LINQ 更新数据库中的记录,该方法可能包含我尚未发现的其他逻辑/语法错误。是什么导致 SubmitChanges 不正确?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
public void updateInfo(RefillViewModel _myRefillViewModel) {
try {
decimal patid = _myRefillViewModel.Patient.Patient_ID;
decimal rxid = _myRefillViewModel.Rx.Rx_ID;
CAHODEntities db = new CAHODEntities();
List<Fill> FillList = db.Fills.Where(p => p.Rx.Rx_ID == rxid && p.Rx.Patient_ID == patid && p.Status == "UnFilled").ToList();
foreach (var item in FillList)
{
if (FillList.Count() == 0)
{
item.Status = "Requested";
}
}
db.SubmitChanges();
}
}
In the method below db.SubmitChanges is shown as invalid/not recognized by intellisense.
This is my first attempt to update records in a database using LINQ and the method may contain other logic/syntactical errors that I havent yet uncovered as well. What is causing the SubmitChanges to be incorrect?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.ComponentModel.DataAnnotations;
using System.Linq.Expressions;
public void updateInfo(RefillViewModel _myRefillViewModel) {
try {
decimal patid = _myRefillViewModel.Patient.Patient_ID;
decimal rxid = _myRefillViewModel.Rx.Rx_ID;
CAHODEntities db = new CAHODEntities();
List<Fill> FillList = db.Fills.Where(p => p.Rx.Rx_ID == rxid && p.Rx.Patient_ID == patid && p.Status == "UnFilled").ToList();
foreach (var item in FillList)
{
if (FillList.Count() == 0)
{
item.Status = "Requested";
}
}
db.SubmitChanges();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你用的是EF吗?因为在实体框架中它是
SaveChanges()
而不是SubmitChanges()
。Are you using EF? Because in Entity Framework it's
SaveChanges()
notSubmitChanges()
.