首页 > 解决方案 > EF Core inherited class data annotation

问题描述

I'm writing a web app using Core 2.0 MVC. With the help of EF I'm trying to create (code first) models to model the database so I can automate the whole db creation process using migration.

My issue, I'm using a third party library to interact with an API (this library was built specifically to interact with this API) but the data that the API returns I'd like to store in a db using the same schema as the class from the library.

As an example Third party library

 public class PersonDetails
 {
     public long PersonID { get; set; }
     public string PersonName { get; set; }
 }

If i try to create a migration for this class it complains about no primary key being set, I'm unable to modify this class. Is there a way that I can set the [Key] attribute for PersonID from an inherited class or something similar?

标签: c#asp.net-core-mvcasp.net-core-2.0

解决方案


推荐阅读