views:

47

answers:

4

i want this bellow syntax write by useing the lamda expression

  from p in this.Context.tblUserInfos
                where p.Status == 1
                select new {p.UserID,p.UserName,p.tblUserType.UserType };

suppose i write

this.Context.tblUserInfos.Where(p => p.Status == 1);

How to write the above syntax by using the => operator.

+1  A: 
this.Context.tblUserInfos.Where(p => p.Status == 1)
            .Select(p => new { p.UserID, p.UserName, p.tblUserType.UserType });
Doug
+1  A: 

Use the .Select IEnumerable extension method to project the result set into an anonymous type.

Like this:

var someAnonymousType = this.Context.tblUserInfos
                             .Where(p => p.Status == 1)
                             .Select(p => new {p.UserID,p.UserName,p.tblUserType.UserType };);
RPM1984
+2  A: 

Well you already have the where portion of it in there so I am assuming you only need the select:

this.Context.tblUserInfos
            .Where(p => p.Status == 1)
            .Select(p => new { p.UserID, p.UserName, p.tblUserType.UserType });
Matt
+1  A: 

LINQPad can convert queries between LINQ and lambda syntax

cxfx