简体   繁体   English

ASP.NET MVC 3中的LINQ to SQL

[英]LINQ to SQL in asp.net MVC 3

What is LINQ for following SQL query for selecting NULL values from ParentCategoryID column: 以下是用于从ParentCategoryID列中选择NULL值的SQL查询的LINQ:

SELECT ID, CategoryName, ParentCategoryID FROM Category 
WHERE (ParentCategoryID IS NULL)

I have try following LINQ but doesn't work: 我尝试跟随LINQ,但不起作用:

from u in db.Categories 
where (u.ParentCategoryID == null) 
select u

make some class, containing fields, those you select (Class1) 制作一些包含您选择的字段的类(Class1)

List<Class1> list = CategoryRepository.Categories
                        .Where(x => x.ParentCategoryId != null)
                        .Select(x => new Class1(x.CategoryName, x.ParentCategoryId)
                        .ToList();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM