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