C# LINQ EF Select

asp.net-mvc-3 entity-framework linq

Question

My project is on MVC3 and I am new to Linq and EF. I'm attempting to do a select and would want to add (Where or if) to exclude a record if a certain item's value is less than 1. the script I used

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

If the PersonID in this scenario is less than 1, this entry should be excluded. I appreciate you.

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

Accepted Answer

Ideally, you should have something that looks like this:

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

The 101 LINQ examples (http://msdn.microsoft.com/en-us/vcsharp/aa336746) are a fantastic place to start learning LINQ.

Cheers to LINQ!



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