T4 template Modifications when the EF Power Tools database is reverse-generated

Source: Internet
Author: User

Reverse Engineer Code first on VS2013 using EF Power Tools is generated backwards.

The decimal (18, 4) field in the discovery database has no precision and scale in the generated mapping class.

This makes the automatically generated SQL default use of decimal (18, 2) when data is saved through EF.

Fortunately EF Power Tools provides the Customize Reverse Engineer Templates and gives the TT files it uses.

Open its mapping.tt.

See

if(Type. Clrequivalenttype = =typeof(int)            || Type. Clrequivalenttype = =typeof(decimal)            || Type. Clrequivalenttype = =typeof( Short)            || Type. Clrequivalenttype = =typeof(Long))        {            if(IsKey && StoreGeneratedPattern! =storegeneratedpattern.identity) {Configlines.add (". Hasdatabasegeneratedoption (Databasegeneratedoption.none)"); }            Else if((!iskey | | efHost.EntityType.KeyMembers.Count >1) && StoreGeneratedPattern = =storegeneratedpattern.identity) {Configlines.add (". Hasdatabasegeneratedoption (databasegeneratedoption.identity)"); }        }    

The decimal did not deal with precision.

Add the following code:

if(Type. Clrequivalenttype = =typeof(decimal))            {                //foreach (var f in Prop. Typeusage.facets)//{                //var scale = (Facet) F; //WriteLine ("//Name: "+ scale.                Name); //}                varScale = (FACET) Prop. TypeUsage.Facets.SingleOrDefault (f = f.name = =" Scale"); varPrecision = (Facet) Prop. TypeUsage.Facets.SingleOrDefault (f = f.name = ="Precision"); Configlines.add (string. Format (". Hasprecision ({0},{1})", precision. Value, scale.            Value)); }

Use reverse Engineer Code first again.

Get the mapping with precision.

            this. Property (t = t.d0)                . Hasprecision (0);             this. Property (t = t.d2)                . Hasprecision (2);             this. Property (t = t.d4)                . Hasprecision (4);

T4 template Modifications when the EF Power Tools database is reverse-generated

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.