After the SubSonic3.0 plug-in creates an object, it compares the updated content with the default value to remove unnecessary update fields and reduce the updated content when assigning values to the object, if the default value is the same as the content of the current update, this column is not submitted for update. This is mainly set when a new record is added because this column is not updated, however, because there are default values in the database, the database automatically determines that the default value is used for filling after submission.
For example, the database has a table Test, the field StatusName nvrchar (10), StatusId int, and the default value is 0. The normal New Record statement is insert into Test (StatusNam, StatusId) values ('name ', 0); but because StatusId has a default value, and the submitted value is equal to the default value, the actual new record statement is insert into Test (StatusNam) values ('name.
The SubSonic3.0 plug-in does not determine whether the current operation is a new operation or a modification operation. Therefore, it does not treat the new operation as a record operation and filters out the operations to modify the status value, the values of these columns cannot be updated as follows:
Open the template file ActiveRecord. tt and find the following code:
<# = Col. cmdype #> <# = CheckNullable (col) #> <# = col. cleanName #> {_ <# = col. cleanName #> (_ <# = col. cleanName #>! = <# = Col. CleanName #> = col = tbl. Columns. SingleOrDefault (x => x. Name = (col! = (! _ DirtyColumns. Any (x => x. Name = col. Name )&&View Code
Modify it
<# = Col. cmdype #> <# = CheckNullable (col) #> <# = col. cleanName #> {_ <# = col. cleanName #> (_ <# = col. cleanName #>! = Value | <# = col. CleanName #> = col = tbl. Columns. SingleOrDefault (x => x. Name = (col! = (! _ DirtyColumns. Any (x => x. Name = col. Name )&&View Code
The modified code is changed:
You can use the SubSonic3.0 plug-in after you generate the source code.
This article is original content. Keep the following information for reprinting.
As long as you want to learn and make progress together, if you are interested, you can add the Q group: SubSonic3.0 Learning Group (327360708) or Email to me (1654937 # qq.com ), I am very busy. If you have any questions, please leave a message first. Please forgive me for not replying in time.
For more questions about SubSonic3.0, refer to the blog: