gpt4 book ai didi

.net - Entity Framework 4.1 - 非键列之间的关系

转载 作者:行者123 更新时间:2023-12-02 03:04:23 25 4
gpt4 key购买 nike

我有 2 个相关的实体,但旧版 SQL 模式本质上有同一个表的 2 个键列(不是 2 列键:见下文)。我需要创建与“假键”列的关系。有没有办法在 Entity Framework 4.1 中以声明方式执行此操作?

Public Class Client
Inherits ModelBase

<Key(), Required()>
Public Property ClientID As Decimal

<Required(), StringLength(50)>
Public Property ClientCode As String

........


Public Class ClientLocation
Inherits ModelBase

........

<Required(), StringLength(50)>
Public Property ClientCode As String

........

<ForeignKey("ClientCode")>
Public Overridable Property Client As Clients.Client

我得到的错误是:

*One or more validation errors were detected during model generation: System.Data.Edm.EdmAssociationConstraint: : The types of all properties in the Dependent Role of a referential constraint must be the same as the corresponding property types in the Principal Role. The type of property 'ClientCode' on entity 'ClientLocation' does not match the type of property 'ClientID' on entity 'Client' in the referential constraint 'ClientLocation_Client'.*

因为它认为我正在尝试映射 ClientLocation.ClientCode > Client.ClientID,而实际上我正在尝试映射 ClientLocation.ClientCode > Client.ClientCode.. .

有什么想法吗?

谢谢!

最佳答案

Entity Framework 要求在主表中的整个主键和从属表中的相应列(外键)之间建立关系。

关于.net - Entity Framework 4.1 - 非键列之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7179405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com