private static void SetStringLength(ModelBuilder modelBuilder, IMutableEntityType entityType, IMutableProperty entityProperty, PropertyInfo propertyInfo) { var maxLength = entityProperty.GetMaxLength(); if (maxLength == null) { modelBuilder.Entity(entityType.Name, b => { var propertyBuilder = b.Property(propertyInfo.Name); var attributes = propertyInfo.GetCustomAttributes(typeof(AutoLengthAttribute), true); if (attributes.Length > 0) { var att = (AutoLengthAttribute)attributes[0]; propertyBuilder.HasMaxLength(att.GetMax()); } else { var theKey = Maps.Keys.FirstOrDefault(x => propertyInfo.Name.EndsWith(x)); if (theKey != null) { propertyBuilder.HasMaxLength(Maps[theKey]); } else { propertyBuilder.HasMaxLength(AutoLengthAttribute.GetMax(AutoLengthCategory.StringNormal)); } } }); } }
// include string foreign keys (also unbound length) public static bool IsUnboundLength(this IMutableProperty prop) { return(prop.GetMaxLength() == null); }