表格定义:
CREATE TABLE [Index].[Dependency] (
[RevisionId] INT NOT NULL,
[MapCode] VARCHAR (10) NOT NULL,
[GroupId] SMALLINT NOT NULL,
[DependencyTypeId] TINYINT NOT NULL,
[InputThreshold] DECIMAL (9, 2) NOT NULL,
[InjectMapCode] VARCHAR (10) NULL,
[InjectAmount] DECIMAL (9, 2) NOT NULL,
CONSTRAINT [UQ_Dependency_RevisionId_MapCode_GroupId] UNIQUE NONCLUSTERED ([RevisionId] ASC, [MapCode] ASC, [GroupId] ASC),
CONSTRAINT [FK_Dependency_MapCode] FOREIGN KEY ([MapCode]) REFERENCES [Index].[Material] ([MapCode]),
CONSTRAINT [FK_Dependency_InjectMapCode] FOREIGN KEY ([InjectMapCode]) REFERENCES [Index].[Material] ([MapCode]),
CONSTRAINT [FK_Dependency_Revision] FOREIGN KEY ([RevisionId]) REFERENCES [Index].[DependencyRevision] ([DependencyRevisionId]),
CONSTRAINT [FK_Dependency_DependencyType] FOREIGN KEY ([DependencyTypeId]) REFERENCES [Index].[DependencyType] ([DependencyTypeId]),
CONSTRAINT [FK_Dependency_Group] FOREIGN KEY ([GroupId]) REFERENCES [Index].[Group] ([GroupId])
);
我试图映射到它:
public class DependencyMap : EntityTypeConfiguration<Entities.Dependency>
{
public DependencyMap()
{
ToTable("Dependency", "Index");
HasKey(md => new { md.RevisionId, md.MapCode, md.GroupId });
Property(s => s.RevisionId).IsRequired().HasColumnName("RevisionId");
Property(s => s.MapCode).IsRequired().HasMaxLength(10).HasColumnName("MapCode");
Property(s => s.GroupId).IsRequired().HasColumnName("GroupId");
Property(s => s.DependencyTypeId).IsRequired().HasColumnName("DependencyId");
Property(s => s.InputThreshold).IsRequired().HasColumnName("InputThreshold").HasPrecision(9, 2);
Property(s => s.InjectMapCode).IsOptional().HasColumnName("InjectEngineMapCode").HasMaxLength(10);
Property(s => s.InjectAmount).HasColumnName("InjectAmount").IsRequired().HasPrecision(9, 2);
}
}
当我尝试调用从表中检索的方法时,会抛出异常
'HasKey(md => new { md.RevisionId, md.MapCode, md.GroupId })'
说&#39;属性表达式无效。表达式应代表一个属性&#39;映射表时。如果有人能告诉我如何在没有明确定义主键的情况下正确映射这样的表,那将非常感激。感谢。