如何使用实体框架获取行的序列号?
我有 SQL 查询:
WITH OrderedRecs AS
(select ROW_NUMBER() OVER(ORDER BY RecID) as seqNumber,* from Records where RecordGroupID=7)
SELECT * FROM OrderedRecs where RecordID=35
如何使用实体框架获得相同的结果?
I have SQL query:
WITH OrderedRecs AS
(select ROW_NUMBER() OVER(ORDER BY RecID) as seqNumber,* from Records where RecordGroupID=7)
SELECT * FROM OrderedRecs where RecordID=35
How do I get the same result using entity framework?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个纯粹的 LINQ 解决方案是:
但是您必须对以下事实感到满意:与第一个条件匹配的所有记录都是在本地获取的。
编辑:
评论后:可能类似于:
其中
SortedRecord
显然现在是一种类型,它使您能够输入各种条件。 (未检查语法)。一种完全不同的方法是在
WITH
子句中创建查询视图。A pure LINQ solution would be:
But than you must be happy with the fact that all records matching the first condition are fetched locally.
Edit:
After you comments: Propably something like:
Where
SortedRecord
, obviously, is a type now, which enables you to enter all kinds of conditions. (syntax not checked).A completely different approach would be to make a view of the query within the
WITH
clause.您不能将 SeqNumber 作为派生(或鉴别器)列添加到基本实体吗? 查看前面的示例。您必须自己分配它。
Couldn't you add SeqNumber as a derived (or discriminator) column to the base entity? See previous example. You would have to assign it yourself.