public static string GenerateSqlCreateFildScript(PropertyInfo info, SqlFieldAttribute sqlField) { //[Id] [int] IDENTITY(1,1) NOT NULL, var identityText = sqlField.Identity ? "IDENTITY(1,1)" : string.Empty; var nullState = "NULL"; if (info.PropertyType.IsGenericType && info.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>) || info.PropertyType == typeof(string)) { nullState = "NOT " + nullState; } return($"[{sqlField.FieldName}] [{ sqlField.FieldDbType.ToString()}] {identityText} {nullState}"); }
public static string GenerateCreateSqlFildScript(this SqlFieldAttribute sqlField, PropertyInfo prop, string entityTable) { var fieldName = sqlField.FieldName ?? prop.Name; string fieldType = sqlField.FieldDbType.ClrType(); if (sqlField.Identity) { return(GenerateCreateSqlIdentityFildScript(fieldName, fieldType, entityTable)); } var nullState = sqlField.Nullable ? "NULL" : "NOT NULL"; return($"[{fieldName}] [{ fieldType }]{sqlField.FieldDbType.ClrLenght()} {nullState}"); }