private string BuilderMethod() { StringPlus plus = new StringPlus(); plus.AppendSpaceLine(2, "#region Method"); //只读 if (IsView) { plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 是否只读"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override bool IsReadOnly()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return true;"); plus.AppendSpaceLine(2, "}"); } ColumnInfo identityColumn = Columns.Find(delegate(ColumnInfo col) { return(col.IsIdentity); }); if (null != identityColumn) { plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取实体中的标识列"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override Field GetIdentityField()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return _." + identityColumn.Name + ";"); plus.AppendSpaceLine(2, "}"); } List <ColumnInfo> primarykeyColumns = Columns.FindAll(delegate(ColumnInfo col) { return(col.IsPrimaryKey); }); if (null != primarykeyColumns && primarykeyColumns.Count > 0) { plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取实体中的主键列"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override Field[] GetPrimaryKeyFields()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return new Field[] {"); StringPlus plus2 = new StringPlus(); foreach (ColumnInfo col in primarykeyColumns) { plus2.AppendSpaceLine(4, "_." + col.Name + ","); } plus.Append(plus2.ToString().TrimEnd().Substring(0, plus2.ToString().TrimEnd().Length - 1)); plus.AppendLine("};"); plus.AppendSpaceLine(2, "}"); } plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取列信息"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override Field[] GetFields()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return new Field[] {"); StringPlus plus3 = new StringPlus(); foreach (ColumnInfo col in Columns) { plus3.AppendSpaceLine(4, "_." + col.Name + ","); } plus.Append(plus3.ToString().TrimEnd().Substring(0, plus3.ToString().TrimEnd().Length - 1)); plus.AppendLine("};"); plus.AppendSpaceLine(2, "}"); plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 获取值信息"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public override object[] GetValues()"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "return new object[] {"); StringPlus plus4 = new StringPlus(); foreach (ColumnInfo col in Columns) { plus4.AppendSpaceLine(4, "this._" + col.Name + ","); } plus.Append(plus4.ToString().TrimEnd().Substring(0, plus4.ToString().TrimEnd().Length - 1)); plus.AppendLine("};"); plus.AppendSpaceLine(2, "}"); plus.AppendSpaceLine(2, "#endregion"); plus.AppendLine(); plus.AppendSpaceLine(2, "#region _Field"); plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 字段信息"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public class _"); plus.AppendSpaceLine(2, "{"); plus.AppendSpaceLine(3, "/// <summary>"); plus.AppendSpaceLine(3, "/// " + TableName + " "); plus.AppendSpaceLine(3, "/// </summary>"); plus.AppendSpaceLine(3, "public readonly static Field All = new Field(\"*\",m_tableName);"); foreach (ColumnInfo col in Columns) { plus.AppendSpaceLine(3, "/// <summary>"); plus.AppendSpaceLine(3, "/// " + col.Name + " " + col.DeText); plus.AppendSpaceLine(3, "/// </summary>"); plus.AppendSpaceLine(3, "public readonly static Field " + col.Name + " = new Field(\"" + col.ColumnNameRealName + "\",m_tableName,\"" + (string.IsNullOrEmpty(col.DeText) ? col.ColumnNameRealName : col.DeText) + "\");"); } plus.AppendSpaceLine(2, "}"); plus.AppendSpaceLine(2, "#endregion"); plus.AppendLine(); return(plus.ToString()); }
public string Builder() { Columns = DBToCSharp.DbtoCSColumns(Columns, DbType); StringPlus plus = new StringPlus(); plus.AppendLine("//------------------------------------------------------------------------------"); plus.AppendLine("// <auto-generated>"); plus.AppendLine("// 此代码由" + System.Reflection.Assembly.GetExecutingAssembly().FullName + "生成;时间 " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture)); plus.AppendLine("// 运行时版本:" + Environment.Version.ToString()); plus.AppendLine("// 不建议手动更改此代码,如有需要请自行扩展partial类"); plus.AppendLine("// </auto-generated>"); plus.AppendLine("//------------------------------------------------------------------------------"); plus.AppendLine(); plus.AppendLine(); plus.AppendLine("using System;"); //plus.AppendLine("using System.Collections.Generic;"); //plus.AppendLine("using System.Data.Common;"); //plus.AppendLine("using System.Linq.Expressions;"); plus.AppendLine("using System.Runtime.Serialization;"); plus.AppendLine("using WEF;"); plus.AppendLine("using WEF.Common;"); plus.AppendLine(); plus.AppendLine("namespace " + NameSpace); plus.AppendLine("{"); plus.AppendLine(); plus.AppendSpaceLine(1, "/// <summary>"); plus.AppendSpaceLine(1, "/// 实体类" + ClassName + ""); plus.AppendSpaceLine(1, "/// </summary>"); plus.AppendSpaceLine(1, $"[Serializable, DataContract, Table(\"{TableName}\")]"); plus.AppendSpaceLine(1, "public partial class " + ClassName + " : Entity "); plus.AppendSpaceLine(1, "{"); plus.AppendSpaceLine(2, "private static string m_tableName;"); plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 实体类" + ClassName + ""); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public " + ClassName + "():base(\"" + TableName + "\") {m_tableName=\"" + TableName + "\";}"); plus.AppendSpaceLine(2, "/// <summary>"); plus.AppendSpaceLine(2, "/// 实体类" + ClassName + ""); plus.AppendSpaceLine(2, "/// <param name=\"dbType\">表名</param>"); plus.AppendSpaceLine(2, "/// </summary>"); plus.AppendSpaceLine(2, "public " + ClassName + "(string tableName):base(tableName) { m_tableName=tableName;}"); plus.AppendLine(); plus.AppendLine(BuilderModel()); plus.AppendLine(BuilderMethod()); plus.AppendSpaceLine(1, "}"); var repositoryCs = BuilderRepository(); if (string.IsNullOrEmpty(repositoryCs)) { return(string.Empty); } plus.AppendLine(repositoryCs); plus.AppendLine("}"); plus.AppendLine(""); return(plus.ToString()); }