我正在使用 linq 从表和视图类中检索 MVC 4 中的数据。如果我使用 linq 从视图中提取数据,如下所示:
db.vwContractMVC.Where(x => x.NID == id && x.Date >= pin && x.Date <= pen).ToList();
然后 linq 使用子查询构造 sql 查询,如下所示:
SELECT
[Extent1].[NID] AS [NID],
[Extent1].[Date] AS [Date],
[Extent1].[Column1] AS [Column1],
[Extent1].[Column2] AS [Column2],
[Extent1].[Column3] AS [Column3]
FROM (SELECT
[vwContractMVC].[NID] AS [NID],
[vwContractMVC].[Date] AS [Date],
[vwContractMVC].[Column1] AS [Column1],
[vwContractMVC].[Column2] AS [Column2],
[vwContractMVC].[Column3] AS [Column3]
FROM [dbo].[vwContractMVC] AS [vwContractMVC]) AS [Extent1]
WHERE ([Extent1].[NID] = @p__linq__0) AND ([Extent1].[Date] >= @p__linq__1) AND ([Extent1].[Date] <= @p__linq__2)
如果使用表 - 查询很简单:
SELECT
[Extent1].[NID] AS [NID],
[Extent1].[Date] AS [Date],
[Extent1].[Column1] AS [Column1],
[Extent1].[Column2] AS [Column2],
[Extent1].[Column3] AS [Column3]
FROM [dbo].[Contract] AS [Extent1]
WHERE ([Extent1].[NID] = @p__linq__0) AND ([Extent1].[Date] >= @p__linq__1) AND ([Extent1].[Date] <= @p__linq__2)
问题是 - 如果可能的话,如何让 linq 从视图中进行简单的选择)
我可以为此创建存储过程,但我希望使用现有的表和视图。