由于我没有自由谈论的几个原因,我们在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.MeterProvingStatisticsPoint'没有定义主键。已推断出键,并且已将定义创建为只读表/视图。
并且它决定CompletedDateTime字段将是该实体的主键。
我们正在使用EdmGen生成模型。有没有一种方法可以使实体框架不包含此视图的任何字段作为主键?