如何使用linq从表中选择 [英] How Select from table using linq

查看:71
本文介绍了如何使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆