开发者

LINQ EF C# Select

开发者 https://www.devze.com 2023-03-24 05:14 出处:网络
I am new to Linq and EF; my project is in MVC3.I am tyring to do a Select, and would like to add (Where or if) to exclude a record when specific item value is less than 1.

I am new to Linq and EF; my project is in MVC3. I am tyring to do a Select, and would like to add (Where or if) to exclude a record when specific item value is less than 1. Here is my script

.Selec开发者_开发知识库t(item => new AreaModel  
        {
            ID = item.ID,
            Name = item.Name,
            PersonID = item.PersonID,
        }) ;

In this case if the PersonID is less than 1 exclude this record. Thanks in advance


you should basically end up with something like:

EntityObject.Where(x => x.PersonID >= 1)
    .Select(item => new AreaModel  
            {
                ID = item.ID,
                Name = item.Name,
                PersonID = item.PersonID,
            });


A good starting point for LINQ are the 101 LINQ samples http://msdn.microsoft.com/en-us/vcsharp/aa336746

Happy LINQ'ing


insert .Where(item => item.PersonID > 0) before .Select.

0

精彩评论

暂无评论...
验证码 换一张
取 消