Reputation: 1
I have the following code in .net framework using EF 6.
PropertyInfo[] propInfo = myObject.GetType().GetProperties(); //myObject is of type T
foreach (PropertyInfo col in propInfo) {
if (col.PropertyType != typeof(System.Data.Entity.Core.EntityKey))
//do something
}
Now that I'm migrating to .Net 5 and EF Core, how do I get the equivalent for typeof(EntityKey)
?
Upvotes: 0
Views: 742
Reputation: 27336
You can achieve this using the following API:
var et = ctx.Model.FindEntityType(typeof(T));
var properties = et.GetProperties();
foreach (var property in properties)
{
if (!property.IsKey())
{
// do something
}
}
Upvotes: 2