DataAnnotations 中 AssociationAttribute 的用途是什么?

out*_*son 2 c# asp.net entity-framework data-annotations

我试图了解是否可以在 EntityFramework 中以某种方式使用 AssociationAttribute。MSDN 文档薄弱。

我在这里找到了一个不确定的答案:

如何使用 System.ComponentModel.DataAnnotations.AssociationAttribute

如果可以的话,请给我一些使用示例。

Nat*_*lus 5

据我所知, AssociationAttribute 用于描述通过业务逻辑关联的业务对象,但来自完全不同的数据上下文(mde 文件)。

例如,如果您的客户类是从 CustomersContext 加载的,但客户类包含驻留在不同数据 Ccontext 中的地址对象,您可以使用此 AssociationAttribute 来装饰客户类中的地址属性来描述:“嘿!加载这个从数据上下文中使用我在属性中提供的名称!”

基本上,框架会将 CRUD 内容委托给地址属性的关联数据上下文。