求助:linq to sql实现数据库数据的更改,报错:无法对属性或索引器“AnonymousType#1.CourseType”赋值-它是只读的

小茜 2012-06-04 10:49:57
public bool save(string no, string typ, int talPer, int talCre, 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;
ObjectQuery<teach_schedule> table_s = EC.teach_schedule;
var records = from b in table_b
join c in table_c
on b.CourseNo equals c.CourseNo
join s in table_s
on b.CourseNo equals s.CourseNo
select new
{
CourseNo = b.CourseNo,
CourseName = b.CourseName,
CourseType = s.CourseType,
TotalPeriod = c.TotalPeriod,
TotalCredit = c.TotalCredit,
CourseSummary = b.CourseSummary,
BookReference = b.BookReference,
PeriodDistribute = b.PeriodDistribute,
TeachDemand = b.TeachDemand
};

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

msg = "请在左边列表框选择要保存的课程教学大纲!";
return false;
}

//插入
if (records.Count() > 0)
{//存在此课程
records.First().CourseType = typ;
records.First().TotalPeriod = talPer;
records.First().TotalCredit = talCre;
records.First().CourseSummary = summa;
records.First().BookReference = refer;
records.First().PeriodDistribute = distr;
records.First().TeachDemand = dema;

if (EC.SaveChanges() > 0)
{
msg = "保存成功!";
return true;
}
}


else
{
//EC.AddTocourse_info(course_bak);//失败则恢复备份记录
EC.SaveChanges();
msg = "保存异常!";
return false;
}
}
catch (Exception ex)
{
msg = ex.ToString();
return false;
}

}
...全文
211 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧