日期:2014-05-20  浏览次数:20809 次

求教简单linq之插入一条记录~各位高手麻烦帮帮忙哈~
public bool save(string no, string summa, string refer, string distr, string dema, ref string msg)
  {

  try
  {
  EntityContainer EC = new EntityContainer();
  ObjectQuery<teach_brief> table_b = EC.teach_brief;
  ObjectQuery<course_info> table_c = EC.course_info;
   
  var records = table_c.Where(c => c.CourseNo.Equals(no));

  if (records.Count() <= 0)
  {//未有该条记录  

  msg = "请在左边列表框选择要保存的课程教学大纲!";
  return false;
  }
   
  if (records.Count() > 0)
  {//存在此课程

  var reco_b = table_b.Where(c => c.CourseNo.Equals(no));
  //插入
  if (reco_b.Count() == 0)
  {
  var newcourbrif = new teach_brief
  {
  CourseNo=no,
  CourseSummary = summa,
  BookReference = refer,
  PeriodDistribute = distr,
  TeachDemand = dema
  };

  table_b.InsertOnSubmit(newcourbrif);//错误: 错误 1
table_b.SubmitChanges();//错误:错误 2 }
  else if (reco_b.Count() > 0)
  {  
  foreach (var brief in reco_b)
  {
  brief.CourseSummary = summa;
  brief.BookReference = refer;
  brief.PeriodDistribute = distr;
  brief.TeachDemand = dema;
  }
  }
   
  if (EC.SaveChanges() > 0)
  {
  msg = "保存成功!";
  return true;
  }
  else 
  {
  msg = "保存失败!";
  return false;

  }
  }
  else
  {
  EC.SaveChanges();
  msg = "保存异常!";
  return false;
  }
  }
  catch (Exception ex)
  {
  msg = ex.ToString();
  return false;
  }
  }
  错误 1 “System.Data.Objects.ObjectQuery<JWGL.Entity.teach_brief>”不包含“InsertOnSubmit”的定义,并且找不到可接受类型为“System.Data.Objects.ObjectQuery<JWGL.Entity.teach_brief>”的第一个参数的扩展方法“InsertOnSubmit”
  错误 2 “System.Data.Objects.ObjectQuery<JWGL.Entity.teach_brief>”不包含“SubmitChanges”的定义,并且找不到可接受类型为“System.Data.Objects.ObjectQuery<JWGL.Entity.teach_brief>”的第一个参数的扩展方法“SubmitChanges”



------解决方案--------------------
table_b.InsertOnSubmit(newcourbrif);//错误: 错误 1 
table_b.SubmitChanges();//错误:错误 2 }
===========
EC.teach_brief.InsertOnSubmit(newcourbrif);
EC.SubmitChanges();