需要与SQL查询等效的Linq [英] Need Linq equivalent of the Sql Query

查看:56
本文介绍了需要与SQL查询等效的Linq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在开发一个使用实体框架数据模型的网站.现在的问题是,在我的数据库中,我有一个使用view
创建的CTE表
开发查询的我的查询如下

Hi Every one

I am developing a website where i have used entity framework data model. Now the problem is that in my data base, i have a CTE table created using view

My Query to develop the query is as under

WITH cte(categoryid, categorytitle, categoryparent, categorydetail,categorycreationdate,categoryinsertedby, categorystatus, companyid, lang)AS (SELECT categoryid,CAST(categorytitle AS VARCHAR(MAX)) AS expr1,categoryparent,categorydetail,categorycreationdate,categoryinsertedby,categorystatus,companyid,lang FROM   dbo.tbl_categories WHERE ( categoryparent = 0 or categoryparent is null)AND ( categorystatus = 1 )UNION ALL SELECT p.categoryid,CAST(c.categorytitle + '>> ' + p.categorytitle AS VARCHAR(MAX)) AS expr1,p.categoryparent,p.categorydetail,p.categorycreationdate,p.categoryinsertedby,p.categorystatus,p.companyid,p.lang FROM   dbo.tbl_categories AS p INNER JOIN cte AS c ON c.categoryid = p.categoryparent) SELECT TOP (100) PERCENT categorytitle, categoryparent,categorydetail, categorycreationdate,categoryinsertedby,categorystatus,companyid, lang,categoryid FROM   cte AS cte_1 ORDER  BY categorytitle ")



我从中生成此查询的表是tbl_Categories
我想要上述查询的等效linq语句.
问候
TanzeelurRehman



The Table from which i am generating this query is tbl_Categories
I want the equivalent linq statement for the above query.
Regards
TanzeelurRehman

推荐答案

检查本文
学习从SQL到LINQ(视觉表示) [
Check this article
Learn SQL to LINQ (Visual Representation)[^]


这篇关于需要与SQL查询等效的Linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆