Create object class, create object

Source: Internet
Author: User

Create object class, create object
Go back to the General Directory, "Step by Step Using the ABP framework to build a formal project series tutorial"

In the previous blog, we created a solution using the ABP template. Now, open the solution, and the directory is shown below:

Next we will go straight to today's topic "create entity class".

An episode: EF DBFirst was always used before we got started with the ABP framework. In that mode, we only need to design the database and then directly generate the entity layer through the template, I didn't even pay much attention to what the code on the entity layer looks like. To use CodeFirst now, you have to write the code first, which is a bit difficult. Well, in order to learn more, you have to stick your head to see what the code looks like, but I don't have to repeat it one by one here, after all, my system has more than 20 entities, which may be increased in the future. It is too time-consuming to knock one by one.Note: Before operating the code, open the Nuget tool to restore all the unloaded assemblies.

Theoretical Study:

The ABP framework provides a definedIdAttributeEntityClass. We can inherit this class to make our object class own this attribute. Note that this Id is of the Int 32 type. If the Id type of your class is not of this type, it doesn't matter. The ABP framework also provides the generic Entity of this class. here T can be any type you want.

Practice:

I have a lot of previously designed tables here, and then I directly generate these entity classes from the database through the dynamic soft code generator. The detailed steps for using the dynamic soft code generator are not the focus of the discussion here. If you are interested, you can find the relevant information by yourself.

Before generating code, I must define an Entity class template Entity. cmt. My template code is as follows:

<#@ template language="c#" HostSpecific="True" #><#@ output extension= ".cs" #><#    TableHost host = (TableHost)(Host);    host.Fieldlist.Sort(CodeCommon.CompareByintOrder);#>using System;using Abp.Domain.Entities;namespace Noah.ChargeStation.Entities<# if( host.Folder.Length > 0) {#>.<#= host.Folder #><# } #>{    <# if( host.TableDescription.Length > 0) {#>     //<#= host.TableDescription #>    <# } #>    public class <#= host.GetModelClass(host.TableName) #>:Entity    {              <# foreach (ColumnInfo c in host.Fieldlist)        {  if(c.ColumnName!="Id")         {             #>/// <summary>        /// <#= string.IsNullOrEmpty(c.Description)  ? c.ColumnName : c.Description #>        /// </summary>        public virtual <#= CodeCommon.DbTypeToCS(c.TypeName) #><# if(c.Nullable) {  #><#if(CodeCommon.isValueType(CodeCommon.DbTypeToCS(c.TypeName))){ #>?<# }#><# }#> <#= c.ColumnName #>        {            get;             set;         }                             <# }} #>        public <#= host.GetModelClass(host.TableName) #>()        {                }       }    }

The next step is to operate the soft code generator to generate a large number of entity classes.

After the code is generated, place the code to the domain layer of the project, that is, the code I generated.

Note: The entity class generation is complete. Next we will create DbContext.

Go back to the General Directory, "Step by Step Using the ABP framework to build a formal project series tutorial"

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.