SrB30
SrB30

Reputation: 1

What is the equivalent for EF6 System.Data.Entity.Core.EntityKey in Entity Framework Core?

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

Answers (1)

Svyatoslav Danyliv
Svyatoslav Danyliv

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

Related Questions