//方法 public class NewsDA { private DataClassesDataContext Context; public NewsDA() { // // TODO: 在此处添加构造函数逻辑 // Context = new DataClassesDataContext(); } //增 public void Insert(News data) { Context.News.InsertOnSubmit(data); Context.SubmitChanges(); } //删 public void Delete(int ids) { News data = Context.News.Single(r => r.newsid ==ids); Context.News.DeleteOnSubmit(data); Context.SubmitChanges(); } //改 public void Updata(News data) { //先去模型中找 News sdata = Context.News.Single(r => r.newsid == data.newsid); //找到后修改 sdata.title = data.title; sdata.author = data.author; sdata.source = data.source; sdata.content = data.content; //提交修改 Context.SubmitChanges(); } //查(1) public List<News> Select() { return Context.News.ToList(); } //查(2) public News Selectbyid(string ids) { return Context.News.Single(r => r.newsid == int.Parse(ids)); } //查(3) public List<News> Selectbytitle(string title) { return Context.News.Where(r => r.title==title).ToList(); }