none
iNSERT command as per Linq RRS feed

  • Question

  • This is my second thread on the subject. The first one was just locked by nobugz, a moderator, who accused me of using "racial slurs."

     

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3731284&SiteID=1

     

    I quote:

     

    That's quite enough racial slurs and disrespect to the contributors to this forum in my book.
    Thread locked.

     

    It is totally unfair and I will file an abuse report with MS on the issue.

     

    The issue was that I critisized the moderator, Samir Bajij, for answering my post perfunctorily. Nobugz took his side and decided to punish me. There were no racial slurs in any posts I posted in there at all and nowhere in any of my MSDN posts ever. Nobugz came up with a baseless fantasy.

     

    In the meantime, my issue remains unresolved. I need help.

     

    Back to the issue:

     

    I have an Sql Server DB on two Sql Servers. On one machine it is Sql Express on the other it is Dev Ed. I have about 50 tables in them which I generated with Smo object. The next thing I did I opened the DB (in a separate routine) and get the table I need as an object. Let's say it is table1.

     

    How can I INSERT values in this table or fill it with rows? The table's schema is as follows. It is dbo. It has 5 columns, all of the VarChar, the first column is indexed and there is a PK on three columns: C1 + C2 + C5. The values are v1, v2, v3, v4, v5. This information is not that important for INSERT to work, of course but I am giving it anyway.

     

    I hope I gave all the information needed to answer my question.

     

    I do have all tutorials at hand, I stored many Linq links in my DB, I've read some of them, I downloaded Linq MSDN samples. It is just too overwhelming to sift thru this mountain and it would be time consuming. I am always in a rush. I hope somebody will give me a helping hand.

     

    By the same tocken, I won't mind to get another hint: how to update values which will be necesseray at the next step.

     

    Thanks.

    Wednesday, August 13, 2008 12:39 PM

Answers

All replies

  • Try to search for "InsertOnSubmit"/"SubmitChanges" methods in one of those tutorials... Basically you "new" the object and call Entity.InsertOnSubmit method or you just update the object you retrieved from the db. Then when you call DataContext.SubmitChanges, updates (and inserts or deletes) are sent to the DB...

     

    Please try being constructive, for now we have no idea what is the problem you have with those tutorials. What have you tried that doesn't work ?

     

    --

    Patrice

     

     

    Wednesday, August 13, 2008 1:55 PM
  • Thank you Patrice.

     

    The problem is simple. The tutorials are based on Norhtwind DB and using dbml files which are created when you attempt to use Linq Query Builder. I posted in this forum that I ran into a problem twice with my attempts to connect Sql Server with VS2008 and this problem did not exist when I had VS2005.

     

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3731393&SiteID=1

     

    Thus I cannot create all those beautiful DB objects diagrams I see in the tutorials EVEN if I had the Northwind. I don't I have it. I have my own DBs. It is not a commercial application. I don't use a standard customer/product dichotomy. I deal with files, their charactersitics, stocks, prices, etc.

     

    I cannot reproduce the objects they are talking about. NorthwindDataContext is not an object for me. My code does not recognize it as a class.

     

    Now, you gave me hope since you mentioned DataContext. At least it is a cue. I think I will go from here.

     

    Patrice, I was as specific as I could when I posted my first thread. Tutorials are fine but it is very hard to study just with tutorials. I have to digest mountains of information daily and I cannot spend a day reading them. This is why people come to this forum as well as others.

     

    Again, I will be specific but please ask specific questions.

     

    I will try to implement what you've suggested and then I will come back.

     

    Thanks.

    Wednesday, August 13, 2008 2:22 PM
  • Much clearer now. Not using SQL Server 2008 but AFAIK you need VS 2008 SP1 available since yesterday (http://msdn.microsoft.com/en-us/vstudio/default.aspx for the SP link). From there you should be able to use the designer to create classes for your db...

     

    --

    Patrice

    Wednesday, August 13, 2008 8:11 PM
  • It is very timelySmile Yes, I don't have Sql Server 2008. I think it is still in Beta (Katmai I believe). I have Sql Serv 2005 Dev Edition. I am downloading SP1 as of now. I hope it helps. Thanks.

    Thursday, August 14, 2008 4:35 PM
  •  Patrice S. wrote:

    Try to search for "InsertOnSubmit"/"SubmitChanges" methods in one of those tutorials... Basically you "new" the object and call Entity.InsertOnSubmit method or you just update the object you retrieved from the db. Then when you call DataContext.SubmitChanges, updates (and inserts or deletes) are sent to the DB...

     

    Please try being constructive, for now we have no idea what is the problem you have with those tutorials. What have you tried that doesn't work ?

    --

    Patrice

     

    Patrice, I found another link that I will try to implement to do the insert which I haven't done yet being busy with other stuff but in the meantime I ran into a problem trying to do InsertOnSubmit. I could not resolve the reference to the method. It is supposed to be in System.Data.Linq namespace. It is among my References in VS2008 as well as among the using directives. Nonetheless I cannot get it in the IntelliSense. It must have been moved but where?

     

    Actually even if I follow the link I quoted aboe I will have to use SubmitChanges ( ) method and I cannot resolve that either. therefore I am stuck. What is the namespace or assembly that holds them?

     

    Thanks.

    Friday, August 15, 2008 1:50 PM
  • Before you can use LINQ to SQL to do anything you need to create a mapping between your objects and the database.

     

    This is normally achieved by using the LINQ to SQL classes project type which will create a DBML file for you to drag the tables across from Server Explorer and then rename/configure how you like. It will also generate the C# or VB.NET datacontext object which will contain the appropriate table objects, SubmitChanges etc.

     

    [)amien

     

    Monday, August 18, 2008 8:12 PM
    Moderator
  • This is normally achieved by using the LINQ to SQL classes project type which will create a DBML file

     

    I tried this a month ago. It killed my access to SSMS. I cannot now sign into the Management Studio. I know all this stuff.

     

    I do have a thread in this forum that describes it.

     

    http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3756772&SiteID=1

     

    How can I reinstall SSMS separately from MSSS? Is it possible in Dev Edition? I know it is possible in Express but I cannot see a way to do it in Dev Edition. It appears to be integrated.

    Thursday, August 21, 2008 12:46 PM