由于以下几个原因,我不便谈论,我们正在 Sql Server 2005数据库上定义一个视图,如下所示:
CREATE VIEW [dbo].[MeterProvingStatisticsPoint]
AS
SELECT
CAST(0 AS BIGINT) AS 'RowNumber',
CAST(0 AS BIGINT) AS 'ProverTicketId',
CAST(0 AS INT) AS 'ReportNumber',
GETDATE() AS 'CompletedDateTime',
CAST(1.1 AS float) AS 'MeterFactor',
CAST(1.1 AS float) AS 'Density',
CAST(1.1 AS float) AS 'FlowRate',
CAST(1.1 AS float) AS 'Average',
CAST(1.1 AS float) AS 'StandardDeviation',
CAST(1.1 AS float) AS 'MeanPlus2XStandardDeviation',
CAST(1.1 AS float) AS 'MeanMinus2XStandardDeviation'
WHERE 0 = 1
这个想法是,实体框架将创建一个基于这个查询的实体,它确实这样做了,但它生成了一个错误,指出以下内容:
警告6002: 表/视图‘ Keystone _ Local。Dbo.MeterProvingStatistics 点’没有定义主键。键已经推断出来,并且定义是作为只读表/视图创建的。
它决定 CompletedDateTime 字段将是这个实体主键。
我们正在使用 EdmGen 来生成模型。是否有一种方法不让实体框架包含此视图的任何字段作为主键?