C# LINQ EF Select

asp.net-mvc-3 entity-framework linq

Question

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

1
2
7/30/2011 7:08:47 PM

Accepted Answer

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,
            });
1
7/30/2011 7:10:47 PM

Popular Answer

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

Happy LINQ'ing



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow