none
Insert / Delete / Update is grayed out. can't insert new record RRS feed

  • Question

  • Hi,

    I have created a simple table that has 3 column: one for primary key and the other 2 are TestName (varchar) and TestValue(int). I then created a simple code to insert new record:


    TestingPerf
    test = new TestingPerf();
    test.TestName =
    "test ";
    test.TestValue = 1;
    db.TestingPerfs.Add(test);
    db.SubmitChanges();

    When i tried compiling it i got:
    Error 1 'System.Data.Linq.Table<TestingDynamicLinq.TestingPerf>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table<TestingDynamicLinq.TestingPerf>' could be found (are you missing a using directive or an assembly reference?) 

    I do have System.Data.Linq in the references list.

    When going to the designer->property the Insert/Update/Delete are grayed out.

    What am i missing?

    Thanks.
    • Edited by kiteSurfer Wednesday, June 17, 2009 6:32 PM
    Wednesday, June 17, 2009 5:21 PM

Answers

  • Change .Add to .InsertOnSubmit.

    With regard the Inserrt/Updater/Delete being grayed out in the designer, this is normal.

    Regards


    Joe

    Write LINQ queries interactively - www.linqpad.net
    • Marked as answer by kiteSurfer Thursday, June 18, 2009 12:20 PM
    Thursday, June 18, 2009 12:20 AM
    Answerer

All replies

  • Change .Add to .InsertOnSubmit.

    With regard the Inserrt/Updater/Delete being grayed out in the designer, this is normal.

    Regards


    Joe

    Write LINQ queries interactively - www.linqpad.net
    • Marked as answer by kiteSurfer Thursday, June 18, 2009 12:20 PM
    Thursday, June 18, 2009 12:20 AM
    Answerer
  • "Add" and "Remove" were changed to "InsertOnSubmit" and "DeleteOnSubmit" prior to the RTM of LINQ to SQL in 2008. You may see earlier references to the older method names which were used through the beta process.

    As for the Add, Insert, and Delete being grayed out in the designer, I assume you are refering to the ASP controls. This will happen if you don't select a full table. If you only select some of the fields from a table, then an anonymous type is generated. Since anonymous types are immutable, the designer doesn't allow you to change these values. If you need to have mutable state, select the full table rather than individual columns.

    Jim Wooley
    www.ThinqLinq.com


    http://www.LinqInAction.net - "LINQ In Action", The book is now available. Don't wait for the movie
    Sunday, June 21, 2009 8:49 PM
    Moderator