diff --git a/src/Scaffolding/VS.Web.CG.EFCore/IPropertyExtensions.cs b/src/Scaffolding/VS.Web.CG.EFCore/IPropertyExtensions.cs index 06a081b93..fe48fa6a1 100644 --- a/src/Scaffolding/VS.Web.CG.EFCore/IPropertyExtensions.cs +++ b/src/Scaffolding/VS.Web.CG.EFCore/IPropertyExtensions.cs @@ -19,20 +19,16 @@ internal static IPropertyMetadata ToPropertyMetadata(this IProperty property, Ty var propertyMetadata = new PropertyMetadata(); propertyMetadata.PropertyName = property.Name; propertyMetadata.TypeName = property.ClrType.FullName; - propertyMetadata.IsPrimaryKey = property.IsPrimaryKey(); // The old scaffolding has some logic for this property in an edge case which is // not clear if needed any more; see EntityFrameworkColumnProvider.DetermineIsForeignKeyComponent propertyMetadata.IsForeignKey = property.IsForeignKey(); - propertyMetadata.IsEnum = property.ClrType.GetTypeInfo().IsEnum; propertyMetadata.IsReadOnly = property.GetBeforeSaveBehavior() != PropertySaveBehavior.Save; - propertyMetadata.IsAutoGenerated = property.ValueGenerated != ValueGenerated.Never || property.GetValueGeneratorFactory() != null; - propertyMetadata.ShortTypeName = TypeUtil.GetShortTypeName(property.ClrType); - propertyMetadata.Scaffold = true; + var declaringEntityType = property.DeclaringType as IEntityType; var reflectionProperty = declaringEntityType?.ClrType.GetProperty(property.Name); if (reflectionProperty != null) @@ -45,6 +41,7 @@ internal static IPropertyMetadata ToPropertyMetadata(this IProperty property, Ty var dataTypeAttr = reflectionProperty.GetCustomAttribute(typeof(DataTypeAttribute)) as DataTypeAttribute; propertyMetadata.IsMultilineText = (dataTypeAttr != null) && (dataTypeAttr.DataType == DataType.MultilineText); + propertyMetadata.IsRequired = reflectionProperty.GetCustomAttribute(typeof(RequiredAttribute)) is not null; } propertyMetadata.IsEnumFlags = false; diff --git a/src/Scaffolding/VS.Web.CG.EFCore/IPropertyMetadata.cs b/src/Scaffolding/VS.Web.CG.EFCore/IPropertyMetadata.cs index 48a005352..f47ca8bd4 100644 --- a/src/Scaffolding/VS.Web.CG.EFCore/IPropertyMetadata.cs +++ b/src/Scaffolding/VS.Web.CG.EFCore/IPropertyMetadata.cs @@ -18,6 +18,7 @@ public interface IPropertyMetadata string ShortTypeName { get; set; } string TypeName { get; set; } bool IsMultilineText { get; set; } + bool IsRequired { get; set; } PropertyInfo PropertyInfo { get; set; } } diff --git a/src/Scaffolding/VS.Web.CG.EFCore/PropertyMetadata.cs b/src/Scaffolding/VS.Web.CG.EFCore/PropertyMetadata.cs index 9246cf5fc..6f5bb399e 100644 --- a/src/Scaffolding/VS.Web.CG.EFCore/PropertyMetadata.cs +++ b/src/Scaffolding/VS.Web.CG.EFCore/PropertyMetadata.cs @@ -73,5 +73,7 @@ public PropertyMetadata(PropertyInfo property) public bool IsMultilineText { get; set; } public PropertyInfo PropertyInfo { get; set; } + + public bool IsRequired { get; set; } } } diff --git a/src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Create.cs b/src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Create.cs index af62f072e..a485b29ac 100644 --- a/src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Create.cs +++ b/src/Scaffolding/VS.Web.CG.Mvc/Templates/Blazor/Create.cs @@ -59,7 +59,7 @@ public virtual string TransformText() this.Write("\" OnValidSubmit=\"Add"); this.Write(this.ToStringHelper.ToStringWithCulture(modelName)); this.Write("\" FormName=\"create\" Enhance>\r\n \r\n " + - " \r\n "); + " \r\n "); foreach (var property in entityProperties) { @@ -68,6 +68,7 @@ public virtual string TransformText() string propertyShortTypeName = property.ShortTypeName.Replace("?", string.Empty); var inputTypeName = Model.GetInputType(propertyShortTypeName); var inputClass = Model.GetInputClassType(propertyShortTypeName); + var requiredAttributeHtml = property.IsRequired ? "aria-required=\"true\"" : string.Empty; this.Write("
\r\n