实体框架和SQL Server视图
由于几个我无权谈论的原因,我们在Sql Server 2005数据库中定义了一个视图,如下所示:
CREATE VIEW [dbo].[MeterProvingStatisticsPoint]ASSELECT 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生成模型。有没有办法不让实体框架包含此视图的任何字段作为主键?
萧十郎
慕码人8056858
相关分类