c# - Add a Column to a Table via Linq or Triggers in SQL -


the issue , got 2 tables x & y. when records added table x , columns should added table y in parallel.

http://prntscr.com/3owqfe <-- provides clear idea.

i tried triggers , seems triggers doesnt allow create table or alter table. anyway i'm using linq , im trying achieve via linq. suggestions ?

edited: record below trigger worked , exception.

create trigger additemtocommon on [sep].[dbo].[itemmaster] insert  begin   declare @payid varchar(max)   select @payid = paycode inserted   alter table [sep].[dbo].[commonpayrollitems]  add samplecol varchar(max)  end  

anyway run once because , there cannot more 1 column of same name. if can retrieve row values grom itemmaster table , it's still possible triggers. tried replace samplecol @payid results in syntax error.

linq not have functionality create or alter tables. use underlying connection of linq datacontext execute sql statement:

datacontext.executecommand(...)

and use run alter table statement. not update linq model of table though.

if plan @ runtime, might want reconsider data model , create third table (eg. stable2extended) contains foreign key both stable , stable2 combined applicable value column.
add stable2extended datamodel , query when need extended properties on stable2 without dynamically modifying tables.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -