开发者

Defining primary key as virtual in Entity Framework

开发者 https://www.devze.com 2023-03-10 11:43 出处:网络
What\'s the benefit of defining the primary key attribute as virtual in entity Framework? AFAIK, virtual is used for lazy loading in navigation properties and for change tracking in other properties.

What's the benefit of defining the primary key attribute as virtual in entity Framework?

AFAIK, virtual is used for lazy loading in navigation properties and for change tracking in other properties. But we don't need any of the mentioned fe开发者_开发技巧atures in primary keys.

So, Is it any use to define primary keys virtual?


Change tracking proxies are created only if all non-navigation mapped properties are virtual. MSDN:

Each property that is mapped to a property of an entity type in the data model must have non-sealed (NotOverridable in Visual Basic), public, and virtual (Overridable in Visual Basic) get and set accessors.

0

精彩评论

暂无评论...
验证码 换一张
取 消