private static void GenerateCSharpRowIntegrate(GenerateIntegrateItem integrateItem, StringBuilder result)
        {
            var fieldNameIdCSharpReferenceList = integrateItem.Owner.ResultReference.Where(item => item.TypeRowIntegrate == integrateItem.TypeRow).Select(item => item.FieldNameIdCSharp).ToList();
            var fieldList = UtilDalType.TypeRowToFieldList(integrateItem.TypeRow);

            foreach (Row row in integrateItem.RowList)
            {
                result.Append(string.Format("                    new {0} {{", integrateItem.TableNameCSharp));
                bool isFirst = true;
                foreach (var field in fieldList)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        result.Append(", ");
                    }
                    object value = field.PropertyInfo.GetValue(row);
                    if (fieldNameIdCSharpReferenceList.Contains(field.FieldNameCSharp) || (fieldNameIdCSharpReferenceList.Count() > 0 && field.FieldNameCSharp == "Id"))
                    {
                        UtilFramework.Assert(value == null || value.GetType() == typeof(int));

                        // Unlike IdName, Id can change from database to database.
                        value = 0;
                    }
                    GenerateCSharpRowIntegrateField(field, value, result);
                }
                result.Append(" },");
                result.AppendLine();
            }
        }
        private static void GenerateCSharpNameEnum(GenerateIntegrateItem integrate, StringBuilder result)
        {
            var fieldList   = UtilDalType.TypeRowToFieldList(integrate.TypeRow);
            var fieldId     = fieldList.SingleOrDefault(item => item.FieldNameCSharp == "Id");     // See also FieldIntegrate.IsKey
            var fieldIdName = fieldList.SingleOrDefault(item => item.FieldNameCSharp == "IdName"); // See also FieldIntegrate.IsKey

            if (fieldIdName != null)
            {
                result.Append(string.Format("        public enum IdEnum {{ [IdEnum(null)]None = 0"));
                List <string> nameExceptList = new List <string>();
                int           count          = 0;
                foreach (Row row in integrate.RowList)
                {
                    count += 1;
                    string idName     = (string)fieldIdName.PropertyInfo.GetValue(row);
                    string nameCSharp = UtilGenerate.NameCSharp(idName, nameExceptList);
                    result.Append(string.Format(", [IdEnum(\"{0}\")]{1} = {2}", idName, nameCSharp, count * -1)); // Count * -1 to ensure there is no relation between enum id and database record id!
                }
                result.AppendLine(string.Format(" }}"));
                result.AppendLine();
                result.AppendLine(string.Format("        public static {0} Row(this IdEnum value)", integrate.TableNameCSharp));
                result.AppendLine(string.Format("        {{"));
                result.AppendLine(string.Format("            return RowList.Where(item => item.IdName == IdEnumAttribute.IdNameFromEnum(value)).SingleOrDefault();"));
                result.AppendLine(string.Format("        }}"));
                result.AppendLine();
                result.AppendLine(string.Format("        public static IdEnum IdName(string value)"));
                result.AppendLine(string.Format("        {{"));
                result.AppendLine(string.Format("            return IdEnumAttribute.IdNameToEnum<IdEnum>(value);"));
                result.AppendLine(string.Format("        }}"));
                result.AppendLine();
                result.AppendLine(string.Format("        public static string IdName(this IdEnum value)"));
                result.AppendLine(string.Format("        {{"));
                result.AppendLine(string.Format("            return IdEnumAttribute.IdNameFromEnum(value);"));
                result.AppendLine(string.Format("        }}"));
                result.AppendLine();
                result.AppendLine(string.Format("        public static async Task<int> Id(this IdEnum value)"));
                result.AppendLine(string.Format("        {{"));
                result.AppendLine(string.Format("            return (await Data.Query<{0}>().Where(item => item.IdName == IdEnumAttribute.IdNameFromEnum(value)).QueryExecuteAsync()).Single().Id;", integrate.TableNameCSharp));
                result.AppendLine(string.Format("        }}"));
                result.AppendLine();
            }
        }
示例#3
0
            /// <summary>
            /// Add from database loaded Integrate rows to generate CSharp code.
            /// </summary>
            /// <param name="isApplication">If true, RowList will be available at runtime as Integrate CSharp code with additional IdEnum if row contains IdName column. If false, RowList will be generated into cli as CSharp code only.</param>
            public void Add <TRow>(IQueryable <TRow> query, bool isApplication = false) where TRow : Row
            {
                var result = GenerateIntegrateItem.Create(this, query, isApplication);

                ResultAdd(result);
            }
示例#4
0
            internal void Add(bool isFrameworkDb, bool isApplication, Type typeRow, IQueryable <Row> query)
            {
                var result = new GenerateIntegrateItem(this, isFrameworkDb, isApplication, typeRow, query);

                ResultAdd(result);
            }
示例#5
0
 private void ResultAdd(GenerateIntegrateItem value)
 {
     Result.Add(value);
 }