Sql 无效的列名\u PK
我有下面的代码,我正在使用ASp.net MVC应用程序Sql 无效的列名\u PK,sql,asp.net,entity,Sql,Asp.net,Entity,我有下面的代码,我正在使用ASp.net MVC应用程序 public class Element { /// <summary> /// Primary Key /// </summary> [Key] public int Pk { get; set; } [ForeignKey("Practice_PK")] [Display(Name = "Practices")] public Practice Practi
public class Element
{
/// <summary>
/// Primary Key
/// </summary>
[Key]
public int Pk { get; set; }
[ForeignKey("Practice_PK")]
[Display(Name = "Practices")]
public Practice Practice { get; set; }
[Display(Name = "Practices")]
public int Practice_PK { get; set; }
每次尝试创建、编辑页面时,我都会收到错误“无效列名Practice_PK”。我知道这个问题已经解决了很多次,但错误本身是如此含糊不清,我不知道如何解决 我刚刚解决了我的问题。返回错误的“Practice\u PK”基本上是针对另一个变量ElementType(不包括上面的代码),该变量属于ElementType类型,应该有Practice\u PK varaible,但没有
Database
CREATE TABLE [dbo].[Elements] (
[Pk] INT IDENTITY (1, 1) NOT NULL,
[Practice_PK] INT NULL,
CONSTRAINT [FK_dbo.Elements_dbo.Practices_Practice_PK] FOREIGN KEY ([Practice_PK]) REFERENCES [dbo].[Practices] ([PK]) ON DELETE CASCADE
);
GO
CREATE NONCLUSTERED INDEX [IX_Practice_PK]
ON [dbo].[Elements]([Practice_PK] ASC);