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
.
精彩评论