public static string GetCreateTableSQL <T>(T t) where T : IEntity { StringBuilder fileds = new StringBuilder(); bool isPrimary = false; Type type = typeof(T); PropertyInfo[] properties = type.GetProperties(); foreach (PropertyInfo property in properties) { Navigation navigationType = (Navigation)Attribute.GetCustomAttribute(property, typeof(Navigation)); if (navigationType != null) { continue; } fileds.AppendFormat("[{0}]", property.Name); fileds.AppendFormat(" [{0}]", TypeConverter.GetSQLType(property.PropertyType)); PropertyType propertyType = (PropertyType)Attribute.GetCustomAttribute(property, typeof(PropertyType)); if (propertyType != null && propertyType.IsPrimaryKey) { isPrimary = true; fileds.AppendFormat(" {0}", PrimaryConverter.GetDefaultPrimaryFiledString()); } if (TypeConverter.IsNullableType(property.PropertyType)) { fileds.AppendFormat(" {0}", DefaultValueConverter.GetDefaultNullValue()); } else { fileds.AppendFormat(" {0}", DefaultValueConverter.GetDefaultNOTNullValue()); } } StringBuilder commandBuilder = new StringBuilder(); commandBuilder.AppendFormat("CREATE TABLE {0} ({1}) ", type.Name, fileds.ToString()); if (isPrimary) { commandBuilder.Append(PrimaryConverter.GetDefaultPrimaryTableEndString()); } return(commandBuilder.ToString()); }