/// <summary> /// 生成实体类的属性 /// </summary> /// <returns></returns> public string CreatModelMethod(List <ColumnInfo> fieldlist) { StringPlus strclass = new StringPlus(); StringPlus strclass1 = new StringPlus(); StringPlus strclass2 = new StringPlus(); strclass.AppendSpaceLine(2, "#region Model"); foreach (ColumnInfo field in fieldlist) { string columnName = field.ColumnName; string columnType = field.TypeName; bool IsIdentity = field.IsIdentity; bool ispk = field.IsPK; bool cisnull = field.cisNull; string deText = field.DeText; columnType = CodeCommon.DbTypeToCS(columnType); string isnull = ""; string devalue = ""; //if (CodeCommon.isValueType(columnType)) //{ // if ((!IsIdentity) && (!ispk) && (cisnull)) // { // isnull = "?";//代表可空类型 // } //} switch (columnType.ToLower()) { case "int": devalue = "0"; break; case "longint": devalue = "0"; break; case "string": devalue = "\"\""; break; case "datetime": devalue = "DateTime.Now"; break; case "bool": devalue = "false"; break; case "decimal": devalue = "0"; break; } strclass1.AppendSpaceLine(2, "private " + columnType + isnull + " _" + columnName.ToLower() + "=" + devalue + ";");//私有变量 strclass2.AppendSpaceLine(2, "/// <summary>"); strclass2.AppendSpaceLine(2, "/// " + deText); strclass2.AppendSpaceLine(2, "/// </summary>"); strclass2.AppendSpaceLine(2, "public " + columnType + isnull + " " + columnName);//属性 strclass2.AppendSpaceLine(2, "{"); strclass2.AppendSpaceLine(3, "set{" + " _" + columnName.ToLower() + "=value;}"); strclass2.AppendSpaceLine(3, "get{return " + "_" + columnName.ToLower() + ";}"); strclass2.AppendSpaceLine(2, "}"); } strclass.Append(strclass1.Value); strclass.Append(strclass2.Value); strclass.AppendSpaceLine(2, "#endregion Model"); return(strclass.Value); }