In Entity Framework 6 I could get the ModelMetadata for a class (myModel) like this:
var modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, myModel.GetType());
How can I do the same in .net core 1.1.1?
ModelMetadataProvider is an ASP.NET feature and it has nothing to do with Entity Framework. In ASP.NET Core you may easily inject a default IModelMetadataProvider
implementation using the built-in DI:
public FooController(IModelMetadataProvider provider)
{
var metadata = provider.GetMetadataForType(typeof(model));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With