就像标题所示我的问题是我有一个查询/存储过程从视图中选择数据并且它在管理工作室工作正常,问题是当我尝试从我的应用程序调用此数据时(使用linq to entites)我得到错误的数据(错误,因为在查询应返回5个不同的行/记录时,单行重复10次) 这是我的管理工作室查询:
select * from dbo.v_RouteCardDetails_SizeInfo
where Trans_TransactionHeader = 0
AND Direction = 0
AND RoutGroupID = 1
AND Degree = '1st'
Size SizeQuantity Trans_TransactionHeader RoutGroupID Direction Degree
XS 10 0 1 0 1st
S 2 0 1 0 1st
M 0 0 1 0 1st
L 5 0 1 0 1st
XXL 2 0 1 0 1st
这是我的Linq查询:
(from x in context.v_RouteCardDetails_SizeInfo
where x.Trans_TransactionHeader == 0
&& x.Direction == 0
&& x.RoutGroupID == 1
&& x.Degree.ToLower() == "1st"
select x).ToList<_Model.v_RouteCardDetails_SizeInfo>();
返回的结果是:
Size SizeQuantity Trans_TransactionHeader RoutGroupID Direction Degree
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
XS 10 0 1 0 1st
连续2天我一直试图解决这个问题,感谢您的帮助 感谢
答案 0 :(得分:4)
毫无疑问,实体框架已经猜到作为视图主键的字段在视图中并不是唯一的。尝试在edmx设计器(或代码优先映射)中向PK添加字段,直到你真正得到一个独特的组合。
EF只为在SQL查询的结果集中找到的每个相同键值实现相同的行。
答案 1 :(得分:1)
因为我建议你做以下事情,所以不可能有环境保护: