Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ to SQL - No Add method available

Tags:

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!

like image 336
Dan Appleyard Avatar asked Apr 15 '09 15:04

Dan Appleyard


People also ask

Which method is valid in LINQ?

Most of the LINQ projection and restriction methods are supported in LINQ to Entities queries, with the exception of those that accept a positional argument. For more information, see Standard Query Operators in LINQ to Entities Queries.

Which join is not supported in LINQ?

LINQ does not support full outer joins directly, the same as right outer joins.

Is LINQ extension method?

All LINQ methods are extension methods, defined in the System.


1 Answers

Table's Add and Remove methods have been renamed to InsertOnSubmit and DeleteOnSubmit.

db.PageHits.InsertOnSubmit(hit); 
like image 61
Steve Willcock Avatar answered Oct 10 '22 08:10

Steve Willcock