hncl
hncl

Reputation: 2295

LINQ EF C# Select

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

.Select(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

Upvotes: 2

Views: 6931

Answers (3)

Thorsten Hans
Thorsten Hans

Reputation: 2683

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

Happy LINQ'ing

Upvotes: 1

nathan gonzalez
nathan gonzalez

Reputation: 11987

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,
            });

Upvotes: 1

user180326
user180326

Reputation:

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

Upvotes: 0

Related Questions