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. Help ---> Select * from Inserted in Linq

Help ---> Select * from Inserted in Linq

Scheduled Pinned Locked Moved LINQ
databasehelpcsharplinqcareer
10 Posts 3 Posters 3 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
    EBeylo
    wrote on last edited by
    #1

    Hi All, i am new in Linq and have a problem; i have a SQLCLR Trigger and its job is to insert the query in another DB (A) after updating it in DB (B), it is like an HistoryLog DB all Updated Queries must be logged in DBHistoy. now i have a mix Code between T_SQL und Linq in my Trigger, it works fine; i get the Datas from my Updates with: 'SELECT * FROM INSERTED' and with Linq i insert them in DBHistory, but i am not happy about this, i want to have only a linq Code inside but i didnt found an equivalent to 'Select * from Inserted' into Linq. please Help ! Thanks in advance...

    H 1 Reply Last reply
    0
    • E EBeylo

      Hi All, i am new in Linq and have a problem; i have a SQLCLR Trigger and its job is to insert the query in another DB (A) after updating it in DB (B), it is like an HistoryLog DB all Updated Queries must be logged in DBHistoy. now i have a mix Code between T_SQL und Linq in my Trigger, it works fine; i get the Datas from my Updates with: 'SELECT * FROM INSERTED' and with Linq i insert them in DBHistory, but i am not happy about this, i want to have only a linq Code inside but i didnt found an equivalent to 'Select * from Inserted' into Linq. please Help ! Thanks in advance...

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      Inserted/deleted are virtual tables that only exist within the context of a trigger. I cannot see how you would ever get LINQ to map to them. I am not even sure that LINQ to SQL is supported in the context of SQL-CLR

      'Howard

      E 1 Reply Last reply
      0
      • H Howard Richards

        Inserted/deleted are virtual tables that only exist within the context of a trigger. I cannot see how you would ever get LINQ to map to them. I am not even sure that LINQ to SQL is supported in the context of SQL-CLR

        'Howard

        E Offline
        E Offline
        EBeylo
        wrote on last edited by
        #3

        well Linq to SQL does support SQL-CLR cause i can create this Trigger without problem and it works fine but like i said i have two Querry after an update : 1. i s_elect * from inserted_ better said from updated and after this 2. i insert them in the other database . the first querry i do it in a T-SQL way and the other Querry in Linq and the Trigger works fine like i want, but to make the performance and the maintainability better i want to make all my Queries in Linq.

        P 1 Reply Last reply
        0
        • E EBeylo

          well Linq to SQL does support SQL-CLR cause i can create this Trigger without problem and it works fine but like i said i have two Querry after an update : 1. i s_elect * from inserted_ better said from updated and after this 2. i insert them in the other database . the first querry i do it in a T-SQL way and the other Querry in Linq and the Trigger works fine like i want, but to make the performance and the maintainability better i want to make all my Queries in Linq.

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

          Why do you think that a LINQ query will be more performant than native SQL in a trigger? I'm a bit confused about this statement, because LINQ ultimately boils down to SQL. So if you have well written SQL, it will be as fast (or possibly faster) than the LINQ equivalent.

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

          My blog | My articles

          E 1 Reply Last reply
          0
          • P Pete OHanlon

            Why do you think that a LINQ query will be more performant than native SQL in a trigger? I'm a bit confused about this statement, because LINQ ultimately boils down to SQL. So if you have well written SQL, it will be as fast (or possibly faster) than the LINQ equivalent.

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

            My blog | My articles

            E Offline
            E Offline
            EBeylo
            wrote on last edited by
            #5

            well i think mixing it, native SQL and Linq in a Trigger maybe cost more time as only Linq or only T-SQL. do you have an idea what is 'Select * from inserted' in Linq ? Thanks for replying..

            P H 2 Replies Last reply
            0
            • E EBeylo

              well i think mixing it, native SQL and Linq in a Trigger maybe cost more time as only Linq or only T-SQL. do you have an idea what is 'Select * from inserted' in Linq ? Thanks for replying..

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

              EBeylo wrote:

              do you have an idea what is 'Select * from inserted' in Linq ?

              Sorry - no, because I would never put LINQ in a trigger. I always do my triggers in pure T-SQL (and frankly, I didn't think it was possible to do LINQ in a trigger; you live and you learn).

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

              My blog | My articles

              E 1 Reply Last reply
              0
              • P Pete OHanlon

                EBeylo wrote:

                do you have an idea what is 'Select * from inserted' in Linq ?

                Sorry - no, because I would never put LINQ in a trigger. I always do my triggers in pure T-SQL (and frankly, I didn't think it was possible to do LINQ in a trigger; you live and you learn).

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

                My blog | My articles

                E Offline
                E Offline
                EBeylo
                wrote on last edited by
                #7

                Pete O'Hanlon wrote: ...(and frankly, I didn't think it was possible to do LINQ in a trigger; you live and you learn). well must first create a new Library Project to get the Linq References and then i generated as an assembly in my Database and with my CLRSQL-Project which i create my Trigger i add this reference and make the linq Code inside. and it works.

                1 Reply Last reply
                0
                • E EBeylo

                  well i think mixing it, native SQL and Linq in a Trigger maybe cost more time as only Linq or only T-SQL. do you have an idea what is 'Select * from inserted' in Linq ? Thanks for replying..

                  H Offline
                  H Offline
                  Howard Richards
                  wrote on last edited by
                  #8

                  Inserted and deleted are virtual tables created by SQL in the context of a trigger. They mirror the structure of the table to which the trigger is attached and represent the data being inserted/updated/deleted. If you have a LINQ to SQL class for the parent table, e.g. Customer then you can use this to obtain SELECT * FROM Inserted thus: var newData = dc.ExecuteQuery<customer>("SELECT * FROM inserted"); However, as Pete O'Hanlon has pointed out using T-SQL for your trigger is going to be MUCH more efficient than any SQL-CLR you write (with or without LINQ). I use LINQ to SQL in my application but not on the database: I'd only use it in a trigger if there was no way whatsoever I could do it in a T-SQL statement.

                  'Howard

                  E 1 Reply Last reply
                  0
                  • H Howard Richards

                    Inserted and deleted are virtual tables created by SQL in the context of a trigger. They mirror the structure of the table to which the trigger is attached and represent the data being inserted/updated/deleted. If you have a LINQ to SQL class for the parent table, e.g. Customer then you can use this to obtain SELECT * FROM Inserted thus: var newData = dc.ExecuteQuery<customer>("SELECT * FROM inserted"); However, as Pete O'Hanlon has pointed out using T-SQL for your trigger is going to be MUCH more efficient than any SQL-CLR you write (with or without LINQ). I use LINQ to SQL in my application but not on the database: I'd only use it in a trigger if there was no way whatsoever I could do it in a T-SQL statement.

                    'Howard

                    E Offline
                    E Offline
                    EBeylo
                    wrote on last edited by
                    #9

                    Howard wrote: If you have a LINQ to SQL class for the parent table, e.g. Customer then you can use this to obtain SELECT * FROM Inserted thus: var newData = dc.ExecuteQuery("SELECT * FROM inserted"); i tried but it throws now an SQL Exception: didnt found an Object with the name INSERTED. now i am convinced and i will make it with the native SQL. thanks

                    H 1 Reply Last reply
                    0
                    • E EBeylo

                      Howard wrote: If you have a LINQ to SQL class for the parent table, e.g. Customer then you can use this to obtain SELECT * FROM Inserted thus: var newData = dc.ExecuteQuery("SELECT * FROM inserted"); i tried but it throws now an SQL Exception: didnt found an Object with the name INSERTED. now i am convinced and i will make it with the native SQL. thanks

                      H Offline
                      H Offline
                      Howard Richards
                      wrote on last edited by
                      #10

                      Doh of course it would! Well my first answer "you can't" stands correct then. You cannot use .ExecuteQuery - it would create a connection to the database using the connection string provided. How on earth one would create a connection to a trigger context I've no idea, and I think Microsoft's answer would be the same as mine - don't. And since Inserted is only visible as part of the trigger context it's never going to be visible to LINQ.

                      'Howard

                      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