Linq to Entities DateTime Conversion [英] Linq to Entities DateTime Conversion

查看:169
本文介绍了Linq to Entities DateTime Conversion的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果给定一个具有DateTime的实体作为字符串,那么在日期过程中使用LINQ to Entities过滤数据的方式是什么?



支持我进行DateTime转换。



基本上,我想完成:

  var filtered = from items in entities.itemsSet 
其中Convert.ToDateTime(shift.starttime)> = startDate
&&& Convert.ToDateTime(shift.endtime)< endDate
选择项;

我有什么选择来完成这个?

  //所以,你会最终在内存过滤中做出决定。首先选择你的数据

var data =(from entities in entities.itemsSet).ToList();


//然后过滤
var filtered = from data in data
其中Convert.ToDateTime(shift.starttime)> = startDate
& & Convert.ToDateTime(shift.endtime)< endDate
选择项;

另一个选择是创建一个存储过程来为您做。在SP中,您必须开始/结束,然后将其与日期时间字符串进行比较。


If given an entity with a DateTime as a string, what are my options to filter the data with LINQ to Entities on the date?

It does not seem to support me doing DateTime conversions.

Basically, I want to accomplish:

var filtered = from item in entities.itemsSet
               where Convert.ToDateTime(shift.starttime) >= startDate 
                   && Convert.ToDateTime(shift.endtime) < endDate
               select item;

What are my options to accomplish this?

解决方案

You are going to end up doing in memory filtering.

//So first select your data

var data= (from item in entities.itemsSet).ToList();


//Then filter
var filtered = from item in data
           where Convert.ToDateTime(shift.starttime) >= startDate 
               && Convert.ToDateTime(shift.endtime) < endDate
           select item;

Another option would be to create a stored procedure to do it for you. In the SP you would have to take start/end and then compare it to your date time strings casted as Date Times.

这篇关于Linq to Entities DateTime Conversion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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