EF Power Tools Reverse Engineer Code First handles calculated fields when you reverse-generate model

Source: Internet
Author: User

Calculated fields are not processed when you reverse-generate model on VS2013 using EF Power tools reverse Engineer Code first. An error occurred while saving the entity.

can be resolved by modifying the mapping.tt.

Open Mapping.tt and find

foreach(varPropinchefHost.EntityType.Properties) {varType =(PrimitiveType) Prop.        Typeusage.edmtype; varIsKey =efHost.EntityType.KeyMembers.Contains (prop); varStoreprop =Efhost.propertytocolumnmappings[prop]; varSgpfacet = StoreProp.TypeUsage.Facets.SingleOrDefault (f = f.name = ="StoreGeneratedPattern"); varStoreGeneratedPattern = Sgpfacet = =NULL?Storegeneratedpattern.none: (StoreGeneratedPattern) Sgpfacet.value; varConfiglines =Newlist<string>(); 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)"); }        }

In var configlines = new list<string>(), after adding the contents of the calculated field:

foreach(varPropinchefHost.EntityType.Properties) {varType =(PrimitiveType) Prop.        Typeusage.edmtype; varIsKey =efHost.EntityType.KeyMembers.Contains (prop); varStoreprop =Efhost.propertytocolumnmappings[prop]; varSgpfacet = StoreProp.TypeUsage.Facets.SingleOrDefault (f = f.name = ="StoreGeneratedPattern"); varStoreGeneratedPattern = Sgpfacet = =NULL?Storegeneratedpattern.none: (StoreGeneratedPattern) Sgpfacet.value; varConfiglines =Newlist<string>(); if(!iskey && StoreGeneratedPattern = =storegeneratedpattern.computed) {Configlines.add (". Hasdatabasegeneratedoption (databasegeneratedoption.computed)"); }                     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)"); }        }

Use reverse Engineer Code first again.

Get the mapping with calculated field information.

            this. Property (t = t.resetdate)                . Hasdatabasegeneratedoption (databasegeneratedoption.computed);             this. Property (t = t.resethour)                . Hasdatabasegeneratedoption (databasegeneratedoption.computed);

EF Power Tools Reverse Engineer Code First handles calculated fields when you reverse-generate model

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.