When the EF Power Tools database is reverse generated, the T4 template is modified, and the eft4

Source: Internet
Author: User
Tags powerdesigner

When the EF Power Tools database is reverse generated, the T4 template is modified, and the eft4

On VS2013, the Reverse Engineer Code First of EF Power Tools is used for Reverse generation.

It is found that the decimal (18, 4) field in the database has no precision or decimal places in the generated mapping class.

This enables the automatically generated SQL statement to use decimal (18, 2) by default when saving data through EF ).

Fortunately, EF Power Tools provides Customize Reverse Engineer Templates, and provides the tt file 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)");            }        }    

Indeed, decimal has no processing 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 );                //}                var scale = (Facet)prop.TypeUsage.Facets.SingleOrDefault(f => f.Name == "Scale");                var precision = (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.

Obtain ing with precision.

            this.Property(t => t.d0)                .HasPrecision(18,0);            this.Property(t => t.d2)                .HasPrecision(18,2);            this.Property(t => t.d4)                .HasPrecision(18,4);

 


How to Use PowerDesigner to reverse engineer and export a database

In the pop-up window, select "COMMENT" and click "COMMENT". In this way, all the tables are like this (the operation is just like operating a template). Step 1: reverse engineering first, file-reverse engineering-DATABASE (load data tables from the DATABASE, field = Information) Select the DATABASE type: for example, if I use oracle 9i, We will select an ODBC data source, as I have already created. If not, we need to create a new one: After the reverse engineering is complete, the generated table is here, and our reverse engineering is complete. First, use question 1 to display the comment information of the table. Then click reports-> reports Wizard. Next, select the generated format. One is the HTML webpage format, and the other is the RTF format, that is, the WORD format, I select a Professional for the print template. I can also select another report template because I found that the report generated by the template contains a lot of content that I don't care about. Next, select the data table first, and then select the table name and Table comments. Pay attention to the sequence and width, for example, 50 MM, then select the columns in the data table, and then set the column name, column type, and column length, select column comments and pay attention to the order and width. For example, you can click 50MM to confirm. --------- Reference ----------------- how to generate a report using PowerDesigner /////////////////////////////// //// // create a new ODBC Data Source ////////////////////// //// // select Database-> configure connections, go to the system dsn tag, click Add, select the database type Oracle, and click Finish. Enter DataSource Name "PDMTest" and ServerName "Database". The configuration is complete. Click "Test Connect" and enter ServerName "Database", user name and password. If the connection is successful, the following figure is displayed, it's almost the same as what I created above :)/////////////////////////////// /// // create a new ODBC Data Source /////////////&#...... remaining full text>

PowerDesigner reverse engineering export oracle database, connection error?

Are you sure you want to use service_name or sid when defining the local service name?

I guess it's service_name.

If yes, then:

Jdbc driver jar files, preferably ojdbc6.jar
Modify the connection string wherever it is:
Jdbc: oracle. thin: @ localhost: 1521/ORCLL Note: Use a slash (/) instead of a colon (:) For Service_name.

If it is SID, you don't know why. You can only doubt your jdbc file or jdk environment problems.


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.