I am new to LINQ. It's my Linq Query Here
var users = from UserTbl in entity.User
from grpTbl in entity.Group
from role in entity.Role
where grpTbl.groupID == UserTbl.groupID&& UserTbl.userID==role.userID
select new Contract.User()
{
UserId = UserTbl.userID,
UserName = UserTbl.userName,
FirstName = UserTbl.firstName,
LastName开发者_运维百科 = UserTbl.lastName,
GroupId = grpTbl.groupID,
GroupName =grpTbl.groupName,
DesignationID = role.roleID
};
How can I write this query in the best way?
it is pretty fine. but I prefer joins
because they make possible to remove "matching" expressions out of where
clause, so that only "true" filtering remains there.
var users = from UserTbl in entity.User
join grpTbl in entity.Group on grpTbl.groupID equals groupId
join role in entity.Role on UserTbl.userID equals role.userID
select new Contract.User()
{
UserId = UserTbl.userID,
UserName = UserTbl.userName,
FirstName = UserTbl.firstName,
LastName = UserTbl.lastName,
GroupId = grpTbl.groupID,
GroupName =grpTbl.groupName,
DesignationID = role.roleID
};
精彩评论