Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. LINQ
  4. What am i missing? Tables in my DataContext do not have Add or Remove options

What am i missing? Tables in my DataContext do not have Add or Remove options

Scheduled Pinned Locked Moved LINQ
databasecomtutorialquestion
8 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    exhaulted
    wrote on last edited by
    #1

    Pretty much what it says in the title, i must be missing something obvious. My "tables" inside my datacontext do not have Remove or Add functions, for example i would like to do something like...

    MyDataContext db = new MyDataContext()
    db.Clients.Add(myCleint);
    db.SubmitChanges();

    but the Add function is not available to me in the db.Clients object. Anyone able to shed some light on this?

    Kev http://esendexdeveloper.spaces.live.com/

    P 1 Reply Last reply
    0
    • E exhaulted

      Pretty much what it says in the title, i must be missing something obvious. My "tables" inside my datacontext do not have Remove or Add functions, for example i would like to do something like...

      MyDataContext db = new MyDataContext()
      db.Clients.Add(myCleint);
      db.SubmitChanges();

      but the Add function is not available to me in the db.Clients object. Anyone able to shed some light on this?

      Kev http://esendexdeveloper.spaces.live.com/

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Add is actually called InsertOnSubmit, and Remove is Delete.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      A 1 Reply Last reply
      0
      • P Pete OHanlon

        Add is actually called InsertOnSubmit, and Remove is Delete.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        A Offline
        A Offline
        Atif Ali Bhatti
        wrote on last edited by
        #3

        Assalam-0-alaikum, Well for that I think u need to know how linqtosql works. then u could have a better idea how to add, update and delete tables in datacontext class. As Soon as u create a linqtosql class(.dbml) its creates a datacontext class and also creates classes for the individual tables that you add in the .dbml class later on. now to insert, you are required to get table from linqtosql class that u have created using following statement. yourDataContextClass datacontext = new yourDataContextClass() ; Table obj = datacontext.getTable(); Now create object on class that has been created for your table as follows. yourTableclass objYourClass = new yourTableclass(); Now add values for the fields. then, obj.InsertOnSubmit(objYourClass); datacontext.submitchanges(); Hope it gives u a bit of idea. Regards, Atif Ali Bhatti.

        A P 2 Replies Last reply
        0
        • A Atif Ali Bhatti

          Assalam-0-alaikum, Well for that I think u need to know how linqtosql works. then u could have a better idea how to add, update and delete tables in datacontext class. As Soon as u create a linqtosql class(.dbml) its creates a datacontext class and also creates classes for the individual tables that you add in the .dbml class later on. now to insert, you are required to get table from linqtosql class that u have created using following statement. yourDataContextClass datacontext = new yourDataContextClass() ; Table obj = datacontext.getTable(); Now create object on class that has been created for your table as follows. yourTableclass objYourClass = new yourTableclass(); Now add values for the fields. then, obj.InsertOnSubmit(objYourClass); datacontext.submitchanges(); Hope it gives u a bit of idea. Regards, Atif Ali Bhatti.

          A Offline
          A Offline
          Atif Ali Bhatti
          wrote on last edited by
          #4

          sorry forgot to mention that u can udpate and delete in the above mentioned manner too. Regards. Atif Ali Bhatti.

          1 Reply Last reply
          0
          • A Atif Ali Bhatti

            Assalam-0-alaikum, Well for that I think u need to know how linqtosql works. then u could have a better idea how to add, update and delete tables in datacontext class. As Soon as u create a linqtosql class(.dbml) its creates a datacontext class and also creates classes for the individual tables that you add in the .dbml class later on. now to insert, you are required to get table from linqtosql class that u have created using following statement. yourDataContextClass datacontext = new yourDataContextClass() ; Table obj = datacontext.getTable(); Now create object on class that has been created for your table as follows. yourTableclass objYourClass = new yourTableclass(); Now add values for the fields. then, obj.InsertOnSubmit(objYourClass); datacontext.submitchanges(); Hope it gives u a bit of idea. Regards, Atif Ali Bhatti.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #5

            I think you meant to post this as a reply to the OP ;) ; I already know this.

            Deja View - the feeling that you've seen this post before.

            My blog | My articles

            A 1 Reply Last reply
            0
            • P Pete OHanlon

              I think you meant to post this as a reply to the OP ;) ; I already know this.

              Deja View - the feeling that you've seen this post before.

              My blog | My articles

              A Offline
              A Offline
              Atif Ali Bhatti
              wrote on last edited by
              #6

              yeah definitely.

              P 1 Reply Last reply
              0
              • A Atif Ali Bhatti

                yeah definitely.

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                Atif Ali Bhatti wrote:

                yeah definitely.

                :-D

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                B 1 Reply Last reply
                0
                • P Pete OHanlon

                  Atif Ali Bhatti wrote:

                  yeah definitely.

                  :-D

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  B Offline
                  B Offline
                  butchzn
                  wrote on last edited by
                  #8

                  Hi Guys, i had the same issue after reading your post i figured it out! Thanks. I thought i would pop some code on it for all to see :-\ hope it helps someone like u guys helped me public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { AddUser(); BindData(); } public UserClass AddUser() { DataClasses1DataContext db = new DataClasses1DataContext(); //Where User is the Class Generated by LINQ that is mapped to my DB Table LinqMapping.User user = new User(); user.Name = "Butch"; user.Surname = "Zn"; user.Active = true; db.Users.InsertOnSubmit(user); db.SubmitChanges(); return null; } public ICollection<UserClass> GetUsers() { DataClasses1DataContext db = new DataClasses1DataContext(); var userList = from u in db.Users select u; ICollection<UserClass> list = new List<UserClass>(); foreach (var user in userList) { list.Add(new UserClass {Id = user.id, FirstName = user.Name, Surname = user.Surname, Active = user.Active}); } return list; } public void BindData() { ICollection<UserClass> user = GetUsers(); GridView1.DataSource = user; GridView1.DataBind(); }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups