How to instruct linq to sql to update table columns to their default values on UpdateOnSubmit/SubmitChanges? -


I have a link for the SQL unit, which emits the following two SQL statements:

  UPDATE [address type] SET [name] = @ P4 WHERE ([surrogate] = @ P) and ([name] = @ P1) and ([last updated] = @ P2) and ( [Last updated] = @ P3) - @ P: Input unique identifier (size = 0; prede = 0; scale = 0) [b0cf44d9-c6ba-de11-b194-001e37f334ea] - @ P1: input warcur (size) = 11; PRESE = 0; scale = 0) [Residencial] - @ P2: Input DateTime (size = 0; PREC = 0; scale = 0) [16/10/2009 23:43:28] - @ P3: Input NVarChar (size = 23; Prec = 0; scale = 0) [Luciano-Nacobiu Lucino] - @ P4: Input Worker (size = 4; prep = 0; scale = 0) [Home] - References: SQL ProvWwder (Sql2008) Model: Attributed Metadald Build: 3.5 .30729.1 UPDATE [IDECT]. [Address type] SET [name] = @ P4 WHERE ([surrogate] = @ P) and ([name] = @ P1) and ([last update] = @ P2) and ([last update] = @ P3) - @ P: Input Unique Identifier (size = 0; PRECI = 0; scale = 0) [B1 CF-44D9-C6B-DE11-B194-001e37f334ea] - @ P1: Input VarChar ( Size = 9; Prec = 0; scale = 0) [comrake] - @ p2: input date time (size = 0; pre = 0; scale = 0) [16/10/2009 23:43:29] - @P 3: Input Encourger (size = 23); Precision = 0; Scale = 0) [Luciano-Nakabuo Lucino] - @ P4: Input Warkar (size = 8; prep = 0; scale = 0) [Business] - Reference: SQL Provider (Sql2008) Model: Attied Erad Module Build: 3.5.30729.1  

But I need a unit to throw sql statements like below, where the last updated and last updated is set to their default values. I think I have to implement Extensibility Method Definition for "partial zero update ..." but I do not know about moving forward. Can anybody help me from there?

  UPDATE [identity]. [Address type] SET [name] = @ P4, [last updated] = default, [last updated] = default where ([([name] = @ p1) and ([last updated] = @ p2) and ([Last Update] = @ P3) - @ P: Input Unique Identifier (size = 0; PRECI = 0; scale = 0) [b0cf44d9-c6ba-de11-b194-001e37f334ea] - @ P1: Input VarChar ( Size = 11; preq = 0; scale = 0) [residencial] - @ p2: input date time (size = 0; prec = 0, scale = 0) [16/10/2009 23:43:28] - @P 3: Input Encourcer (size = 23; prep = 0; scale = 0) [Luciano-Nakabuo \ Luciano] - @ P4: Input VarChar = [4]; Prec = 0; Scale = 0) [Home] - Reference: SqlProvider (Sql2008) Model: Attitated Matamodel Build: 3.5.30729.1 UPDATE [Identification]. [Address Type] SET [Name] = @ P4, [Last UPDEDON] = default, [last updated] = default where ([surrogate] = @ P) and ([name] = @ P1) and ([last updated] = @ P2) and ([last update] = @ P3) - @ p: Input unique identifier (size = 0; precie = 0; scale = 0) [b1cf44d9-c6ba-de11-b194-001e37f334ea] - @ p1: input warcur (size = 9; pre = 0; Scale = 0) [comrake] - @ p2: input date time (size = 0; prec = 0; scale = 0) [16/10/2009 23:43:29] - @ P3: input NVarChar (size = 23) SqlProvider (Sql2008) Model: Integrated Matermodel Build - Prec = 0; Scale = 0) [Luciano Nauto - Louisiana] - @ P4: Input VarChar (Size = 8; Prec = 0; Scale = 0) [Business] - Reference: : 3.5.30729.1  

Regards, INSERT create a new record I / P>

.

If you want to update your LastUpdateOn and LastUpdateBy columns for each update, you do not apply it anytime, then You probably have to pay attention to using triggers to handle it or highlight them as the properties of your entity / institutions so that you can determine the program before the update statement is executed.

Linux-to-SQL gives you several extension points to hook up - e.g. On Validate method on your unit class:

  Partial zero on-validate (System.Data.Linq.ChangeAction operation) {if (action == ChangeAction.Update) Set your last update and last updated values}}  

Or you can apply partial method OnUpdate (entity) to your class and You can set the fields as needed:

  Partial Zero UpdateEmployee (employee example) {// Set ExecuteDynamicUpdate (example) on your LastUpdatedBy and LastUpdatedOn values ​​here; }  

Another option is explained by using a utility class for auditing.

Mark


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -