Codesmith generates entity-Layer Code

Source: Internet
Author: User

<% --
Name: dd
Author: Binbin
Description: booksir
-- %>
<% @ Codetemplate Language = "C #" targetlanguage = "text" src = "" inherits = "" DEBUG = "false" Description = "template description here." %>
<% @ Assembly name = "schemaexplorer" %>
<% @ Import namespace = "schemaexplorer" %>
<% @ Assembly name = "system. Data" %>
<% @ Import namespace = "system. Data" %>
<% @ Property name = "sourcetable" type = "schemaexplorer. tableschema" Category = "context" Description = "select a table" %>
<% @ Property name = "namespace" type = "system. string "default =" somevalue "Optional =" true "Category =" strings "Description =" program namespace "%>
Using system;
Using system. Web;
Using system. Data;
Namespace <% = namespace %>
{
Public class <% = onetoupper (sourcetable. Name) %> info
{
<% For (INT I = 0; I <sourcetable. Columns. Count; I ++) {%>
Private <% = getcsharpvariabletype (sourcetable. Columns [I]) % >_< % = onetolower (sourcetable. Columns [I]. Name) %>;
<% }%>

<% For (INT I = 0; I <sourcetable. Columns. Count; I ++) {%>
Public <% = getcsharpvariabletype (sourcetable. Columns [I]) %> <% = onetoupper (sourcetable. Columns [I]. Name) %>
{
Get {return _ <% = onetolower (sourcetable. Columns [I]. Name) %> ;}
Set {_ <% = onetolower (sourcetable. Columns [I]. Name) %> = value ;}
}
<% }%>
}

}
<SCRIPT runat = "template">
// Uppercase letters
Private string onetoupper (string Str)
{
Return Str. substring (0, 1). toupper () + Str. substring (1 );
}
// Lowercase for the first letter
Private string onetolower (string Str)
{
Return Str. substring (0, 1). tolower () + Str. substring (1 );
}

Public String getcsharpvariabletype (columnschema column)
{
If (column. Name. endswith ("typecode") return column. Name;

Switch (column. datatype)
{
Case dbtype. ansistring: Return "string ";
Case dbtype. ansistringfixedlength: Return "string ";
Case dbtype. Binary: Return "byte []";
Case dbtype. boolean: Return "bool ";
Case dbtype. byte: Return "Byte ";
Case dbtype. Currency: Return "decimal ";
Case dbtype. Date: Return "datetime ";
Case dbtype. datetime: Return "datetime ";
Case dbtype. Decimal: Return "decimal ";
Case dbtype. Double: Return "double ";
Case dbtype. guid: Return "guid ";
Case dbtype. int16: Return "short ";
Case dbtype. int32: Return "int ";
Case dbtype. int64: Return "long ";
Case dbtype. Object: Return "object ";
Case dbtype. sbyte: Return "sbyte ";
Case dbtype. Single: Return "float ";
Case dbtype. String: Return "string ";
Case dbtype. stringfixedlength: Return "string ";
Case dbtype. Time: Return "timespan ";
Case dbtype. uint16: Return "ushort ";
Case dbtype. uint32: Return "uint ";
Case dbtype. uint64: Return "ulong ";
Case dbtype. varnumeric: Return "decimal ";
Default:
{
Return "_ Unknown _" + column. nativetype;
}
}
}
</SCRIPT>

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.