• 主页
  • ASP
  • .NET Framework
  • Web Services
  • VB
  • VC
  • 图表区
  • 分析与设计
  • 组件/控件开发
  • LINQ
mindsky 2014年07月03日
[焦头烂额]Linq to entity和视图的执行结果不一样,求解惑!!!
本人有一视图:

SELECT row_number() OVER (ORDER BY dbo.zaojia_gclqd.[file_name]) AS ID, dbo.zaojia_gclqd.[file_name], max(dbo.zaojia_gclqd.create_datetime)
AS create_datetime, '工程量清单' AS tablename
FROM dbo.zaojia_gclqd
GROUP BY dbo.zaojia_gclqd.[file_name]
UNION ALL
SELECT row_number() OVER (ORDER BY dbo.zaojia_gclzhibiao.[file_name]) AS ID, dbo.zaojia_gclzhibiao.[file_name],
max(dbo.zaojia_gclzhibiao.create_datetime) AS create_datetime, '工程量指标' AS tablename
FROM dbo.zaojia_gclzhibiao
GROUP BY dbo.zaojia_gclzhibiao.[file_name]
UNION ALL
SELECT row_number() OVER (ORDER BY dbo.zaojia_rgdj.[file_name]) AS ID, dbo.zaojia_rgdj.[file_name], max(dbo.zaojia_rgdj.create_datetime)
AS create_datetime, '人工单价' AS tablename
FROM dbo.zaojia_rgdj
GROUP BY dbo.zaojia_rgdj.[file_name]
UNION ALL
SELECT row_number() OVER (ORDER BY dbo.zaojia_zhibiao.[file_name]) AS ID, dbo.zaojia_zhibiao.[file_name], max(dbo.zaojia_zhibiao.create_datetime)
AS create_datetime, '造价指标' AS tablename
FROM dbo.zaojia_zhibiao
GROUP BY dbo.zaojia_zhibiao.[file_name]
UNION ALL
SELECT row_number() OVER (ORDER BY dbo.cost_analysis.[file_name]) AS ID, dbo.cost_analysis.[file_name], max(dbo.cost_analysis.create_datetime)
AS create_datetime, '分析报告' AS tablename
FROM dbo.cost_analysis
GROUP BY dbo.cost_analysis.[file_name]


作用就是过滤每张表的file_name字段,取不重复的值,最后把几张表的结果union一下,现在发现在SQL查询分析器里得到的结果正确,是:
1 1.xlsx 2014-07-03 09:13:48.003 工程量清单
2 2.xlsx 2014-07-03 09:16:01.020 工程量清单
3 3.xlsx 2014-07-03 09:17:34.527 工程量清单
4 4.xlsx 2014-07-03 09:21:20.133 工程量清单
5 工程量清单模版.xlsx 2014-07-02 16:48:05.203 工程量清单
1 file1 2014-07-01 11:42:18.007 工程量指标
1 file1 2014-07-01 14:43:18.203 人工单价
1 造价指标模版.xlsx 2014-07-03 14:00:49.477 造价指标

但是在Linq to entity里执行结果不正确,变成:
1 1.xlsx 2014-07-03 09:13:48.003 工程量清单
1 1.xlsx 2014-07-03 09:13:48.003 工程量清单
1 1.xlsx 2014-07-03 09:13:48.003 工程量清单
1 1.xlsx 2014-07-03 09:13:48.003 工程量清单
1 1.xlsx 2014-07-03 09:13:48.003 工程量清单
1 file1 2014-07-01 11:42:18.007 工程量指标
1 file1 2014-07-01 14:43:18.203 人工单价
1 造价指标模版.xlsx 2014-07-03 14:00:49.477 造价指标

经分析,同事认为是因为实体没有主键引起的,问题是这个SQL语句我不知道怎么来指定主键,
最后没有办法在linq里用db.ExecuteStoreQuery()这个直接传SQL语句解决了
现在请教大神如果直接在linq to entity里,应该如何解决这个问题呢??
...全文
94 点赞 收藏 3
写回复
3 条回复

还没有回复,快来抢沙发~

发动态
发帖子
.NET技术社区
创建于2007-09-28

4.8w+

社区成员

66.8w+

社区内容

.NET技术交流专区
社区公告
暂无公告