我有2个表,REGISTRATION和STATUS_CODE
CREATE TABLE [dbo].[REGISTRATION](
[REG_ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL PRIMARY KEY,
[TYPE] [char](1),
[CREDIT_STATUS] [varchar](4) NULL,
[CREDIT_STATUS2] [varchar](4) NULL,
[CREDIT_STATUS_TEMP] AS (case when [TYPE] = '1' then [CREDIT_STATUS] when [TYPE] = '2' then [CREDIT_STATUS2] end)
)
CREATE TABLE [dbo].[STATUS_CODE](
[STATUS_CODE] [varchar](4) NOT NULL PRIMARY KEY,
[STATUS_DESC] [varchar](10),
)
我的最终目标是使用EF
运行以下查询SELECT REG.REG_ID, STS.STATUS_DESC FROM [dbo].[REGISTRATION] REG
INNER JOIN [dbo].[STATUS_CODE] STS
ON REG.CREDIT_STATUS_TEMP = STS.STATUS_CODE
WHERE STS.STATUS_DESC LIKE '%FAILED%'
在C#中,我在REGISTRATION类中为计算列
提供了以下注释...
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[ForeignKey("CreditStatusTemp")]
[StringLength(4)]
public string CREDIT_STATUS_TEMP { get; private set; }
public virtual STATUSC_CODE CreditStatusTemp { get; set; }
...
但是,每当我尝试保存REGISTRATION记录时。 我会遇到这个错误。
{"A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'CREDIT_STATUS_TEMP'."}
我知道我需要FK注释才能执行查询,但我不确定如何正确执行。请帮忙,谢谢。