SQL到LINQ转换 [英] SQL to LINQ Conversion

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

问题描述

您好我正在尝试将此SQL查询转换为linq查询。请帮忙

选择*来自
(SELECT optionsMenu.menuID,optionsMenu.MenuName,optionsMenu.parentMenuID,optionsMenu.MenuKey,
optionsMenu.Description,optionsMenu.SortOrder,optionsMenu.VideoPath,
optionsParentMenu.menuName as parentMenuName,optionsLanguages.languageID,optionsLanguages.language
FROM optionsMenu Inner Join optionsMenu as optionsParentMenu on optionsMenu.ParentMenuID = optionsParentMenu.menuID
Left Join optionsLanguages On optionsMenu.languageID = optionsLanguages.languageID
WHERE( optionsMenu.parentMenuID IN
(SELECT menuID FROM optionsMenu AS optionsMenuTemp WHERE(parentMenuID = 3))))作为optionsMenu


ctrlnick

解决方案

我开发了以下内容,但是我希望它返回一个字符串列表

请让我知道什么是可能的

顺便说一下,foreach循环中的查询返回一次多行


    var   menuIDQuery   =     from   oMenu   in   db    OptionsMenu   
其中 oMenu ParentMenuID == 3
select oMenu ;

foreach < span class = kwd> var m in menuIDQuery
{

var query = from opMenu in db OptionsMenu
join opParentMenu
in db OptionsMenu < span class = pln> on opMenu ParentMenuID equals opParentMenu MenuID
其中 opMenu ParentMenuID == m MenuID
select new
{

opMenu
MenuName

};


}

结果


Hi I am trying to convert this SQL query to linq query . Please help

Select * From
(SELECT optionsMenu.menuID, optionsMenu.MenuName, optionsMenu.parentMenuID, optionsMenu.MenuKey,
optionsMenu.Description, optionsMenu.SortOrder, optionsMenu.VideoPath,
optionsParentMenu.menuName as parentMenuName, optionsLanguages.languageID, optionsLanguages.language
FROM optionsMenu Inner Join optionsMenu as optionsParentMenu on optionsMenu.ParentMenuID = optionsParentMenu.menuID
Left Join optionsLanguages On optionsMenu.languageID = optionsLanguages.languageID
WHERE (optionsMenu.parentMenuID IN
(SELECT menuID FROM optionsMenu AS optionsMenuTemp WHERE (parentMenuID = 3)))) as optionsMenu


ctrlnick

解决方案

I developed the below , But I want it to return a List of Strings

Please let me know what is possible

and by the way , The query in the foreach loop returns more than one rows at a time


var menuIDQuery = from oMenu in db.OptionsMenu
                             
where oMenu.ParentMenuID == 3
                             
select oMenu;
 
           
foreach (var m in menuIDQuery)
           
{
 
               
var query = from opMenu in db.OptionsMenu
                            join opParentMenu
in db.OptionsMenu on opMenu.ParentMenuID equals opParentMenu.MenuID
                           
where opMenu.ParentMenuID == m.MenuID
                           
select new
                           
{
                               
                                opMenu
.MenuName,
                               
                           
};
 
 
               
           
}



这篇关于SQL到LINQ转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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