LINQ (VS2008) - Add Method on DataContext not defined?

I have played around with LiNQ for a while now and I have been using the visual express editions until now. Today however, I installed VS2008 and tried to startup my LiNQ demo project for my manager. Suddenly I couldn’t Add new entries to various classes and the error VS2008 was giving me was:

“Error    1    ‘System.Data.Linq.Table<DBML.Player>’ does not contain a definition for ‘Add’ and no extension method ‘Add’ accepting a first argument of type ‘System.Data.Linq.Table<DBML.Player>’ could be found (are you missing a using directive or an assembly reference?)    C:\Documents and Settings\steve\My Documents\Visual Studio 2008\WebSites\GenLeague_new\Controls\Players\PlayerDetail.ascx.cs    61    42    C:\…\GenLeague_new\”

Now this confused me because the following code works perfectly in Visual Web Developer 2008:

newPlayerContext.Players.Add(_player);

In Visual Studio 2008 however, this line of code should read as follows:

newPlayerContext.Players.InsertOnSubmit(_player);

Why there is a difference between VS2008 and the express Web Developer Version is a mystery to me.

Blogged with Flock

Tags: , ,

Posted under General by StevenMcD on Thursday 6 December 2007 at 5:06 pm

11 Comments »

  1. Comment by Idetrorce — December 15, 2007 @ 2:08 pm

    very interesting, but I don’t agree with you
    Idetrorce

  2. Comment by StevenMcD — December 20, 2007 @ 8:50 pm

    Well, when i try to compile code with the .Add() method I get a compiler error, yet when I put .InsertOnSubmit() it works with no problems.

  3. Comment by Joe — January 9, 2008 @ 6:53 pm

    I would also like to know the answer to this inconsistency. I didn’t use web dev 08 for linq yet but many code examples had .Add which in VS08 wasn’t compiled into my DataContext class. (for Idetrorce)I am not really sure how you “don’t agree” unless you simply have some different version of VS08.

    Anyway Steven thanks for the tip on the InsertOnSubmit() instead.

  4. Comment by Joe — January 9, 2008 @ 7:25 pm

    http://blogs.msdn.com/jongallant/archive/2007/12/01/linq-add-renamed-to-insertonsubmit.aspx

  5. Comment by StevenMcD — January 13, 2008 @ 4:38 pm

    Hey Joe,

    Thanks for the comments and the link! MS really should include this type of change in their newsletters. What is still weird that one method works in the Express editions and the other in VS. Strange!!!!

  6. Comment by Antonio — January 30, 2008 @ 9:59 pm

    Thank you both Steve and Joe.

  7. Comment by StevenMcD — January 31, 2008 @ 6:09 am

    Glad to have helped Antonio

  8. Comment by Ikhwan — February 15, 2008 @ 7:25 am

    Hi. I’ve been hit by the same problem too. Thanks for the solution Steven.

    But anyway, I still interested to know what really happen. Anybody can shed a light?

  9. Comment by StevenMcD — February 15, 2008 @ 9:46 am

    I have no idea, all the MVPs I have asked have no idea or wasn’t aware that there was a difference! I think we need to put this down to a MS change that just wasn’t correctly broadcast. These things happen though and as developers I think we should just roll with the changes and find the solutions as we encounter these small problems! Thanks for the comment :)

  10. Comment by Darshit Dave — March 10, 2008 @ 3:58 am

    I am agree with you that Add method is renamed to InsertOnSubmit(). The other useful method is InsertAllOnSubmit() which accepts a list of records (objects).

  11. Comment by fornetti — August 31, 2008 @ 4:25 am

    I do not believe this

RSS feed for comments on this post. TrackBack URI

Leave a comment