I am customizing the Entity Framework ASP.NET CRUD templates used for Add=>New Scaffolded Item...=>" MVC 5 Controller with views, using Entity Framework". I am also using the [ComplexType] attribute with classes that are used for entity properties (for example, a [ComplexType] FullName class is used for a SpouseFullName property in my Customer entity class).
public class Customer
{
public string CustomerNumber { get; set; }
public FullName SpouseFullName { get; set; }
}
[ComplexType]
public class FullName
{
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public FullName()
{
FirstName = "";
MiddleName = "";
LastName = "";
}
}
I would like to be able to iterate over the property metadata for each property in my [ComplexType] when scaffolding. For example:
<#
IEnumerable<PropertyMetadata> properties = ModelMetadata.Properties;
foreach (PropertyMetadata property in properties)
{
// Is this a [ComplexType]?
if(property.IsComplexType)
{
// Iterate over metatdata here.
}
}
Ideally, I would like to be able to get an IEnumerable<PropertyMetadata>
of properties contained in my [ComplexType]. Ideas?