//private static string GetModelFieldString(ColumnObjectModel column)
        //{

        //}

        private static string GetModelPropertyString(ColumnObjectModel column)
        {
            string sqlDataType = EntityModelScript.IsNullable(column) ?
                                 $"{EntityModelScript.GetSqlDataMap(column.SqlDataType.Value)}{(column.InPrimaryKey ? string.Empty : "?")}" :
                                 EntityModelScript.GetSqlDataMap(column.SqlDataType.Value);

            string inPrimaryKey = column.InPrimaryKey ? "(Primary Key) " : string.Empty;

            string isForeignKey = column.IsForeignkey ? $"(Foreign Key from: {column.ForeignKeyTable}) " : string.Empty;

            string description = $"{inPrimaryKey}{isForeignKey}{column.Description}";

            if (column.SqlDataType.Value == SqlDbType.Timestamp)
            {
                string resultSting = EntityModelScript.Setup.ModelPropertyString
                                     .Replace("{0}", description)
                                     .Replace("{1}", sqlDataType)
                                     .Replace("{2}", EntityModelScript.GetColumnName(column));

                int insertIndex = resultSting.IndexOf("</summary>") + 10;

                resultSting = resultSting.Insert(insertIndex, $"{Environment.NewLine}        [Timestamp]");

                return(resultSting.ToString());
            }

            // NOTE: We need to do a replace due to the brackets in the text here
            return(EntityModelScript.Setup.ModelPropertyString
                   .Replace("{0}", description)
                   .Replace("{1}", sqlDataType)
                   .Replace("{2}", EntityModelScript.GetColumnName(column)));
        }
 public static string[] GetColumnDotNetDescriptor(ColumnObjectModel column)
 {
     return(new string[]
     {
         EntityModelScript.GetSqlDataMap(column.SqlDataType.Value),
         EntityModelScript.GetColumnName(column)
     });
 }
        public static string ScriptServerModelMapping(TableModel table)
        {
            StringBuilder result = new StringBuilder();

            result.AppendLine(Setup.MappingClassUsing);

            result.AppendLine();

            result.AppendLine($"namespace {Setup.MappingClassNamespace}");

            result.AppendLine("{");

            result.AppendLine($"    public class {EntityModelScript.GetClassName(table)}Mapping : EntityTypeConfiguration<{EntityModelScript.GetClassName(table)}>");
            result.AppendLine("    {");

            result.AppendLine($"        public {EntityModelScript.GetClassName(table)}Mapping()");
            result.AppendLine("        {");

            result.AppendLine($"            ToTable(\"{table.TableName}\");");
            result.AppendLine();

            ColumnObjectModel[] pkColumns = table.Columns.Where(pk => pk.InPrimaryKey).ToArray();

            if (pkColumns.HasElements() && pkColumns.Length == 1)
            {
                result.AppendLine($"            HasKey(k => k.{EntityModelScript.GetColumnName(pkColumns[0])});");
            }
            else if (pkColumns.HasElements())
            {
                result.Append("            HasKey(k => new { ");

                for (int x = 0; x < pkColumns.Length; ++x)
                {
                    if (x == (pkColumns.Length - 1))
                    {
                        result.Append($"k.{EntityModelScript.GetColumnName(pkColumns[x])} ");
                    }
                    else
                    {
                        result.Append($"k.{EntityModelScript.GetColumnName(pkColumns[x])}, ");
                    }
                }

                result.AppendLine(" });");
            }

            result.AppendLine();

            for (int x = 0; x < table.Columns.Length; x++)
            {
                ColumnObjectModel column = table.Columns[x];

                string lambda = $"col{x}";

                result.AppendLine($"            Property({lambda} => {lambda}.{EntityModelScript.GetColumnName(column)}).HasColumnName(\"{column.ColumnName}\");");
            }

            result.AppendLine("        }");

            result.AppendLine("    }");

            result.Append("}");

            return(result.ToString());
        }