LINQ to SQL的 - 没有可用的Add方法 [英] LINQ to SQL - No Add method available
本文介绍了LINQ to SQL的 - 没有可用的Add方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个LINQ to SQL的DataContext的,在一个单一的数据表。我想简单地插入新记录到该表中。我穿过来的问题是LINQ是不是提供了一个Add方法在新的记录来传递。我见过无数的例子,有一个Add方法,但我似乎无法得到它。我是彻底失去了一些东西或者是其他什么东西?
I have created a LINQ to SQL datacontext with a single datatable in it. I am trying to simply insert a new record into that table. The problem I am coming across is LINQ is not offering an Add method to pass in the new record to. I have seen countless examples where there is an Add method, but I can't seem to get it. Am I completely missing something or is it something else?
using (praetoriaTestDataContext db = new praetoriaTestDataContext())
{
PageHit hit = new PageHit();
hit.DateViewed = DateTime.Now;
hit.Page = "test";
db.PageHits.Add(hit); //Add method is not available!
db.SubmitChanges();
}
谢谢!
Thanks!
推荐答案
表的添加和删除方法已更名为InsertOnSubmit和DeleteOnSubmit。
Table's Add and Remove methods have been renamed to InsertOnSubmit and DeleteOnSubmit.
db.PageHits.InsertOnSubmit(hit);
这篇关于LINQ to SQL的 - 没有可用的Add方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文