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. LINQ to SQL - TSQL Output statement equivalent

LINQ to SQL - TSQL Output statement equivalent

Scheduled Pinned Locked Moved LINQ
questioncsharpdatabasesql-serverlinq
5 Posts 4 Posters 10 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.
  • S Offline
    S Offline
    Simon_Whale
    wrote on last edited by
    #1

    I testing LINQ to SQL to see if it is the right tool for an application. My question is as follows; In SQL 2005 and later you get to use the Output clause^] i.e.

    create table t ( i int not null );
    create table t_audit ( old_i int not null, new_i int null );
    insert into t (i) values( 1 );
    insert into t (i) values( 2 );

    update t
    set i = i + 1
    output deleted.i, inserted.i into t_audit
    where i = 1;

    delete from t
    output deleted.i, NULL into t_audit
    where i = 2;

    select * from t;
    select * from t_audit;

    drop table t, t_audit;
    go

    Does anyone know of a LINQ to SQL equivalent? If so any good articles to read?

    As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

    D S 2 Replies Last reply
    0
    • S Simon_Whale

      I testing LINQ to SQL to see if it is the right tool for an application. My question is as follows; In SQL 2005 and later you get to use the Output clause^] i.e.

      create table t ( i int not null );
      create table t_audit ( old_i int not null, new_i int null );
      insert into t (i) values( 1 );
      insert into t (i) values( 2 );

      update t
      set i = i + 1
      output deleted.i, inserted.i into t_audit
      where i = 1;

      delete from t
      output deleted.i, NULL into t_audit
      where i = 2;

      select * from t;
      select * from t_audit;

      drop table t, t_audit;
      go

      Does anyone know of a LINQ to SQL equivalent? If so any good articles to read?

      As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

      D Offline
      D Offline
      dasblinkenlight
      wrote on last edited by
      #2

      There is no LINQ to SQL equivalent for this feature. As a side note, I would not use LINQ to SQL on a new project, because Microsoft pretty much deprecated it in favor of Entity Framework. Unfortunately, there is no direct equivalent to "output" in EF either. However, both LINQ to SQL and EF let you define stored procedures to be used for inserting, updating, and deleting your entities. Of course, inside these stored procedures you have unrestricted access to features of the underlying database, so you can write to your audit table from there.

      S 1 Reply Last reply
      0
      • S Simon_Whale

        I testing LINQ to SQL to see if it is the right tool for an application. My question is as follows; In SQL 2005 and later you get to use the Output clause^] i.e.

        create table t ( i int not null );
        create table t_audit ( old_i int not null, new_i int null );
        insert into t (i) values( 1 );
        insert into t (i) values( 2 );

        update t
        set i = i + 1
        output deleted.i, inserted.i into t_audit
        where i = 1;

        delete from t
        output deleted.i, NULL into t_audit
        where i = 2;

        select * from t;
        select * from t_audit;

        drop table t, t_audit;
        go

        Does anyone know of a LINQ to SQL equivalent? If so any good articles to read?

        As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

        S Offline
        S Offline
        Shahriar Iqbal Chowdhury Galib
        wrote on last edited by
        #3

        Hi, You can check this tool, LinqPad[^]. Its very handy for developers.

        S 1 Reply Last reply
        0
        • S Shahriar Iqbal Chowdhury Galib

          Hi, You can check this tool, LinqPad[^]. Its very handy for developers.

          S Offline
          S Offline
          Simon_Whale
          wrote on last edited by
          #4

          Thanks for that it looks like it could be a usefull tool. But from others responding to my question and research, I found that I couldn't do an equivilent linq to sql version of the SQL Server 2005 / 2008 OUTPUT statement.

          As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.

          1 Reply Last reply
          0
          • D dasblinkenlight

            There is no LINQ to SQL equivalent for this feature. As a side note, I would not use LINQ to SQL on a new project, because Microsoft pretty much deprecated it in favor of Entity Framework. Unfortunately, there is no direct equivalent to "output" in EF either. However, both LINQ to SQL and EF let you define stored procedures to be used for inserting, updating, and deleting your entities. Of course, inside these stored procedures you have unrestricted access to features of the underlying database, so you can write to your audit table from there.

            S Offline
            S Offline
            s_poorghaz
            wrote on last edited by
            #5

            :)

            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