예제 #1
0
        /// <summary>
        /// 创建模型主体
        /// </summary>
        /// <param name="structs"></param>
        /// <returns></returns>
        private string CreateBody(string tableName, List <TableStruct> structs)
        {
            StringBuilder builder = new StringBuilder();

            builder.Append("[Serializable]\r\n");
            builder.Append("public partial class " + tableName + "\r\n");
            builder.Append("{\r\n");
            builder.Append("\r\n");
            builder.Append("#region private field \r\n");
            builder.Append("\r\n");
            foreach (var t in structs)
            {
                builder.Append("private " +
                               GeneratorTools.SqlTypeName2DotNetType(t.DATA_TYPE) +
                               " _" + t.COLUMN_NAME + ";\r\n");
            }
            builder.Append("\r\n");
            builder.Append("#endregion \r\n");
            builder.Append("\r\n");
            foreach (var t in structs)
            {
                if (t.ISPRIMARY)
                {
                    builder.Append("[Key]\r\n");
                }
                string COLUMN_NAME = t.COLUMN_NAME;
                string COLUMN_BODY = "{get{return " + "_" + COLUMN_NAME + ";}set{" + "_" + COLUMN_NAME + "=value;}}\r\n";
                builder.Append("public " + GeneratorTools.SqlTypeName2DotNetType(t.DATA_TYPE) + " " +
                               COLUMN_NAME + COLUMN_BODY);
                builder.Append("\r\n");
            }
            builder.Append("}\r\n");
            return(builder.ToString());
        }