我如何将其转换为Linq [英] How Do I Convert This To Linq

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

问题描述

如何将此SQL转换为Linq



how to convert this SQL to Linq

SELECT Catergories FROM UserCategories
WHERE [Id]=2

推荐答案

要么:

Either this:
var selectedCategories =
    from uc in UserCategories
    where uc.Id == 2
    select uc.Categories;



或者:


Or this:

var selectedCategories =
    UserCategories.Where(uc => uc.Id == 2)
                  .Select(uc => uc.Categories);



Repla ce UserCategories 包含您想要的数据对象。


Replace UserCategories with the data object that you want.


假设您正在使用Entity Framework,您可以这样做:



Assuming you are using Entity Framework, you would do something like this:

var categories = context.Categories.Where(c => c.Id == 2);


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

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