Exemplo n.º 1
0
        public static string ConverTablenameToGetEntitiesStoredProcedureName(string tablename)
        {
            string entityName, prefix;

            GetEntitynameAndPrefixByTablename(tablename, out entityName, out prefix);
            return(string.Format("up_{0}{2}_Get{1}", prefix, PluralizerHelper.ToPlural(entityName), entityName));
        }
Exemplo n.º 2
0
        public static string ToPlural(this string rawText)
        {
            if (string.IsNullOrEmpty(rawText))
            {
                return(rawText);
            }

            return(PluralizerHelper.ToPlural(rawText));
        }
 public GetEntitiesDAFunc(string entityClass, string storedProcedureName, Column idColumn, string FunName)
     : base(
         string.Format("Get{0}", PluralizerHelper.ToPlural(FunName))
         , "void", null)
 {
     this.entityClass         = entityClass;
     this.storedProcedureName = storedProcedureName;
     this.idColumn            = idColumn;
     paramIds        = idColumn.Name.ToFirstLower().ToPlural();
     paramEntities   = PluralizerHelper.ToPlural(entityClass.ToFirstLower());
     this.Parameters = new List <FunctionParameter>();
     this.Parameters.Add(new FunctionParameter(paramIds, string.Format("{0}[]", idColumn.CSTypeName)));
     this.Parameters.Add(new FunctionParameter(paramEntities, string.Format("ref Dictionary<{0}, {1}>", idColumn.CSTypeName, entityClass)));
 }
Exemplo n.º 4
0
        public static string GenerateKVStoreManagerCode(string entityClass, Column idColumn)
        {
            StringBuilder code          = new StringBuilder();
            string        paramEntities = PluralizerHelper.ToPlural(entityClass.ToFirstLower()) + "Cache";

            code.AppendLineFormatWithTabs("static KVStoreEntityTable<{0}, {1}> {2} = KVStoreManager.GetKVStoreEntityTable<{0}, {1}>(\"{2}\", 180, 10000);", 1
                                          , idColumn.CSTypeName, entityClass, paramEntities);
            code.AppendLineFormatWithTabs("public static KVStoreEntityTable<{0}, {1}> {2}", 1
                                          , idColumn.CSTypeName, entityClass, paramEntities.ToFirstUpper());
            code.AppendLineWithTabs("{", 1);
            code.AppendLineFormatWithTabs("get {{ return {0}; }}", 2, paramEntities);
            code.AppendLineFormatWithTabs("set {{ {0} = value; }}", 2, paramEntities);
            code.AppendLineWithTabs("}", 1);
            return(code.ToString());
        }
Exemplo n.º 5
0
        public static string GenerateDataAccessOfGetEntities(string entityClass, string storedProcedureName, Column idColumn)
        {
            string paramIds      = idColumn.Name.ToFirstLower().ToPlural();
            string paramEntities = PluralizerHelper.ToPlural(entityClass.ToFirstLower());

            StringBuilder code = new StringBuilder();

            //code.AppendLineWithTabs("/// <summary>", 0);
            //code.AppendLineFormatWithTabs("/// 填充{0}集合", 0, entityClass);
            //code.AppendLineWithTabs("/// </summary>", 0);
            //code.AppendLineFormatWithTabs("/// <param name=\"{0}\"></param>", 0, paramIds);
            //code.AppendLineFormatWithTabs("/// <param name=\"{0}\"></param>", 0, paramEntities);
            code.AppendLineFormatWithTabs("public void Get{0}({2}[] {1}, ref Dictionary<{2}, {3}> {4})", 0
                                          , PluralizerHelper.ToPlural(entityClass), paramIds
                                          , idColumn.CSTypeName, entityClass, paramEntities);
            code.AppendLineWithTabs("{", 0);

            code.AppendLineFormatWithTabs("if ({0} == null)", 1, paramEntities);
            code.AppendLineFormatWithTabs("{0} = new Dictionary<{1}, {2}>();", 2
                                          , paramEntities, idColumn.CSTypeName, entityClass);
            code.AppendLine();

            code.AppendLineWithTabs("using (SqlConnection conn = GetSqlConnection())", 1);
            code.AppendLineWithTabs("{", 1);
            code.AppendLineFormatWithTabs("using (SqlDataReader dr = SqlHelper.ExecuteReader(conn, \"{0}\",", 2, storedProcedureName);
            code.AppendLineFormatWithTabs("new SqlParameter(\"@Ids\", SqlHelper.ConvertIdsToXML<{0}>(\"e\", {1}))", 4, idColumn.CSTypeName, paramIds);
            code.AppendLineWithTabs("))", 3);
            code.AppendLineWithTabs("{", 2);
            code.AppendLineWithTabs("while (dr.Read())", 3);
            code.AppendLineWithTabs("{", 3);
            code.AppendLineFormatWithTabs("{0} {1} = new {0}(dr);", 4, entityClass, entityClass.ToFirstLower());
            code.AppendLineFormatWithTabs("{0}[{1}.{2}] = {1};", 4, paramEntities, entityClass.ToFirstLower(), idColumn.Name);
            code.AppendLineWithTabs("}", 3);
            code.AppendLineWithTabs("dr.Close();", 3);
            code.AppendLineWithTabs("conn.Close();", 3);
            code.AppendLineWithTabs("}", 2);
            code.AppendLineWithTabs("}", 1);

            code.AppendLineWithTabs("}", 0);

            return(code.ToString());
        }