Why can't i use DataAnnotations KeyAttribute for composite keys?

c# entity-framework-core

Question

EntityFramework Core restricts using KeyAttribute for defining composite keys. But what is the reason for this limitation? I have found a solution for this without using Fluent api.

1
-1
3/29/2019 11:35:14 AM

Accepted Answer

According to this GitHub Issue it is in the backlog to be implemented in the upcoming version of EF Core. And from this GitHub Issue, here is the explanation that you were looking for:

The reason is that it used a combination of Key and Column for ordering, but column ordering is not the same thing as key ordering, and so this caused confusion and issues in EF6. Changing existing data annotations is also costly because of their relationship to .NET Core and .NET Framework.

However, we see the value in being able to this and other common configuration using attributes, since the jump to the fluent API can be a big one. Therefore, we will investigate creating a new library/package with additional new EF configuration attributes that can be used alongside data annotations. This would be one of the things that would be implemented there.

However, According to this announcement, from ASP.NET Core 3.0 you can use all the features of EF 6.x with ASP.NET Core as there will be EF 6.3 on .NET Core >= 3.0

1
3/29/2019 12:13:21 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow