I have refactored an application which uses EF5 Database First. The application uses metadata classes to add data annotations to the entity properties. Before the refactor, these worked. They are mostly just display names and data formats.
Example:
[MetadataType(typeof(QueryDetailsResultMetadata))]
public partial class QueryDetailsResult : IPortfolio
{
public string Source { get { return "Local"; } }
}
public class QueryDetailsResultMetadata
{
//Fields from QueryDetailsResult requiring annotations
[Display(Name = "Company Name")]
public string SiteName { get; set; }
[Display(Name = "Contact Telephone Number")]
public string ContactTelNo { get; set; }
}
Before the refactor, the partial class did not inherit from an interface and it did not have the non mapped property. These changes are however required. Neither of these two should be causing a problem as both are well documented as valid solutions.
The interface looks like this
public interface IPortfolio
{
int Id { get; set; }
string SiteName { get; set; }
string YearOfManufacture { get; set; }
string Contact { get; set; }
string ContactTelNo { get; set; }
string Source { get;}
}
The display uses the properties like this
@Html.DisplayNameFor(model => model.Portfolio.ContactTelNo)
On the View at runtime, the property names are shown rather than the display names. Any ideas why? I can't see any reason for the annotations to be broken
//edit
I tried moving the annotations on to the new non-mapped fields in the partial and removed them from the metadata class. To seee if it had any effect. None. Also double checked the edmx is in the same Namespace as the partial class and metadata file which it is.
Any thoughts on what to check or try? Not having much success this end, most google results are just saying to use a metadata class which is already in place.
//2nd Edit
Moving annotations out of metadata class and on to the interface did the trick.