【发布时间】:2010-11-15 13:12:46
【问题描述】:
我在将以下 t-sql 语句转换为 Linq(使用 4.0 实体框架)时遇到了一点问题
我来了
无法转换类型 'System.Linq.IOrderedQueryable
1' to type 'System.Linq.IQueryable1'。 LINQ to Entity 仅支持强制转换 实体数据模型原语类型。
T-Sql
SELECT
I.Id
, I.Name
FROM Inventory I
WHERE I.Id in
(
select top 5 applicationId
from LastViewed
group by ApplicationId, SomeUserId
having SomeUserId = @SomeUserId
order by Max(id) desc
)
这就是我现在所拥有的(在 Linqer 的帮助下)
Dim query As IQueryable(Of Inventory) =
From d In ctx.Inventories
Where
((From e In ctx.LastVieweds _
Group e By _
e.ApplicationId, _
e.SomeUserId _
Into g = Group _
Where DfaitEdsId = user _
Order By g.Max(Function(p) p.Id) Descending _
Select New With { _
ApplicationId _
}).Take(5)).Contains(New With {.ApplicationId = d.Id}) _
Select d
当我执行此行时,它当前崩溃。
query.ToList()
感谢您的宝贵时间。
【问题讨论】:
-
我在这里遇到了类似的问题:stackoverflow.com/questions/4416887/…。我怀疑 VB.Net 编译器是罪魁祸首,因为我可以让它在 C# 中工作。您能否提供更多背景信息,以便我们尝试重现您的问题(请解释
DfaitEdsId和user是什么)?
标签: asp.net vb.net linq entity-framework linq-to-entities