When the SubSonic3.0 plug-in uses entities for Update operations (execute T. Update () or T. Save (), some Columns cannot be modified.

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.