Linq左连接 使用大于小于匹配
我现在遇到这样一个问题,我有一张表是记录登陆日志的,里面有个一个IP字段,还有一种IPAddress表记录某段IP所在的区域,这个表里有一个开始Ip和结束IP,表示在这两个IP之间的IP地址都属于这个地区,现在的问题是用Linq怎么实现 大于小于符号匹配 而不是equals
下面的代码就是我要表达的意思,只不过这么写是不对的 在线等....
--------------------编程问答-------------------- 补充下,把下面的SQL 转换成Linq就可以了
var result = from ul in dc.GetTable<UserLog>()
join ip in dc.GetTable<IPAddress>() on ul.LogIp >= ip.StartIP && ul.LogIp <= ip.EndIP
where ul.LogTime >= Convert.ToDateTime(startDate) && ul.OffLineTime <= Convert.ToDateTime(endDate)
select ul;
--------------------编程问答-------------------- 这个你的情 用 linq 的人了,我是不用 linq 这个东西,所以不知道。 --------------------编程问答-------------------- 遍历dc.GetTable<UserLog>()集合,
select ua.NickName,ip.Address,ul.LogTime from UserLog as ul
inner join IPAddress as ip on ul.LogIp >= ip.StartIP and ul.LogIp <= ip.EndIP
inner join UserAccount as ua on ul.UserId = ua.Id
dc.GetTable<IPAddress>().Where(x => x.LogTime >= Convert.ToDateTime(startDate)&& ul.OffLineTime <= Convert.ToDateTime(endDate) && .....) --------------------编程问答-------------------- 遍历太慢了,还有其他方法吗? --------------------编程问答-------------------- 有没有高手在啊,我很着急啊。 --------------------编程问答--------------------
--------------------编程问答-------------------- 好的谢谢 不过IP是string类型 在Linq中不能比较 --------------------编程问答-------------------- 6楼还在吗? --------------------编程问答-------------------- 自己写个方法比较IPhttp://blog.csdn.net/pojianbing/article/details/2234144
//你可以这样:
var result = from ul in dc.GetTable<UserLog>()
from ip in dc.GetTable<IPAddress>()
where ul.LogIp >= ip.StartIP && ul.LogIp <= ip.EndIP && ul.LogTime >= Convert.ToDateTime(startDate) && ul.OffLineTime <= Convert.ToDateTime(endDate)
select ul;
补充:.NET技术 , ASP.NET