如何使用linq从表中选择 [英] How Select from table using linq
问题描述
如何向用户选择最后的对话消息从Id 1的下表可能在FromId或ToId中
< pre lang =css> MessageId FromId ToId 消息 时间 状态
19 1 5 hiii 2013-07-05 16:39:49 . 727 新
21 5 1 消息 2013-07-10 11:19:53 。 733 新
25 5 1 dfdfdf 2013-07-07 00:00:00 。 000 新
29 1 8 dsfas 2013-07 -07 00:00:00 。 000 新
30 8 1 asdfjas 2013-07-07 02:00:00 。 000 新
必需输出: -
MessageId FromId ToId消息时间状态
21 5 1消息2013-07-10 11:19:53.733新
30 8 1 asdfjas 2013-07-07 02:00:00.000新
一个简单的linq查询,用于选择ToId等于1的行(如所需输出)
DateTime start = new DateTime( 2013年1月1日);
var result =( from a in new YourDataContext()。YourTableName
where ((a.ToId == < span class =code-digit> 1 || a.FromId == 1 )&& a.Time > = start)
选择 a);
如果不是您的意图,请再解释一下,我们将提供;)
祝你好运,
Edo
var ResultData = 来自数据 db.TableName
其中 Data.FromId == 1
选择数据;
其中db = DataclassDataContext()
关于您的ID的所有数据都在ResultData变量....:)
How can i select last conversation messages to users From below table of Id 1 that may be in FromId or ToId
MessageId FromId ToId Message Time Status
19 1 5 hiii 2013-07-05 16:39:49.727 New
21 5 1 message 2013-07-10 11:19:53.733 New
25 5 1 dfdfdf 2013-07-07 00:00:00.000 New
29 1 8 dsfas 2013-07-07 00:00:00.000 New
30 8 1 asdfjas 2013-07-07 02:00:00.000 New
Required Output:-
MessageId FromId ToId Message Time Status
21 5 1 message 2013-07-10 11:19:53.733 New
30 8 1 asdfjas 2013-07-07 02:00:00.000 New
A simple linq query that selects the rows where the ToId equals 1 (as in your "required output")
DateTime start = new DateTime("1/1/2013"); var result = (from a in new YourDataContext().YourTableName where ((a.ToId == 1 || a.FromId == 1) && a.Time >= start) select a);
If it's not what you intended, explain a little more, and we will provide ;)
Good luck,
Edo
var ResultData = from Data in db.TableName where Data.FromId==1 select Data;
where db=DataclassDataContext()
All the data regarding your ID is in ResultData variable....:)
这篇关于如何使用linq从表中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!