使用LINQ选择多个字段 [英] Select multiple fields with LINQ
本文介绍了使用LINQ选择多个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
请帮帮我。
我需要用linq查询表并绑定从中返回的行对象的linq查询
hi
pls help me.
I need to query a table with linq and bind the rows returned from the linq query to an object
WebChatDBDataContext dataContext = new WebChatDBDataContext();
var executiveSession= dataContext.ExecutiveSessions.FirstOrDefault(s => s.SessionId == httpcontext.Session.SessionID);
var talkerId = (from cRoom in dataContext.ChatRooms
where cRoom.ExecutiveId == executiveSession.ExecutiveSessionId
select cRoom.TalkerId
);
var msglst = from msgPool in dataContext.MessagePools
where msgPool.TalkerId == ???// who has talkerId which is selected by last query
select msglst;
推荐答案
你可以在这里使用连接。查看此链接有关 LINQ [ ^ ]。
基本上,你是希望在TalkerId上将ChatRooms加入MessagePools。
You could use joins here. Check this link about LINQ[^].
Basically, you are looking to join ChatRooms to MessagePools on TalkerId.
这篇关于使用LINQ选择多个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文