在所选日期内查找交易 [英] Find transaction within selected date

查看:58
本文介绍了在所选日期内查找交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我使用日期和时间选择器查找交易(从日期和日期开始)



由于日期和时间的时间部分,我遇到的问题并非所有交易都在显示。

但我需要的只是显示datefrom和Enddate之间日期的所有交易,无论时间如何。



我需要它对象格式不是字符串格式。



这就是我使用的:



  DateTime   FromDate   =  日期时间。现在; 

DateTime EndDate = DateTime 。现在;







  var 事务=(来自 c  in  context.JobCards 
where (c.TransDateRequired > FromDate)&&(c.TransDateAdded < EndDate)
选择 c) .ToList();







我也试图截断时间



  var 交易=(来自 c  context.JobCards 
其中(EntityFunctions.TruncateTime(c.TransDateRequired)> EntityFunctions.TruncateTime(FromDate))&& (EntityFunctions.TruncateTime(c.TransDateRequired)< EntityFunctions.TruncateTime(EndDate))
select c);





截断时间我得到以下错误



 LINQ to Entities无法识别方法'System.Nullable`1 [System.DateTime] TruncateTime(System.Nullable`1 [System.DateTime])'方法,并且此方法无法转换为商店表达< br /> 



提前感谢您的任何帮助。

解决方案

您可以构建您的查询通过使用lambda表达式,如下一个示例所示,并且应该可以工作:

  var  Transaction = context.JobCards。 Where(c = >  EntityFunctions.TruncateTime(c.TransDateRequired)>  EntityFunctions.TruncateTime(FromDate) )&& (EntityFunctions.TruncateTime(c.TransDateRequired)<  EntityFunctions.TruncateTime(EndDate))); 


< blockquote>试试这个:

  //  从日期列开始在数据库表中接受null  
// 使其可为空
DateTime?FromDate = DateTime.Now;

DateTime?EndDate = DateTime.Now;

var 交易=(来自 c in context.JobCards
where (c.TransDateRequired > = FromDate
&&
c.TransDateAdded < = EndDate)
select c).ToList();



- 艾米


我所做的是格式化选择dateandtime以便时间总是凌晨12点,



现在从它开始使用所选日期并结束它将使用日期+1天到凌晨12:00。 />


所以selecetion只会是选择之间的日期。



感谢您的帮助和建议


Hi,

I use a date and time picker to find transaction( From date & To date)

I am having the issue that not all the transaction are displaying because of the time portion of the dateandtime.
But what i need is simply to display all transactions of the dates between datefrom and Enddate regardless of the time.

And i need it in object format not string format.

this is what i use :

DateTime FromDate =  DateTime.Now;

DateTime EndDate = DateTime.Now;




var Transaction = (from c in context.JobCards
                   where (c.TransDateRequired > FromDate) && (c.TransDateAdded < EndDate)
                   select c).ToList();




I Also tried to truncate the time

var Transaction = (from c in context.JobCards
                   where (EntityFunctions.TruncateTime(c.TransDateRequired) > EntityFunctions.TruncateTime(FromDate)) && (EntityFunctions.TruncateTime(c.TransDateRequired) < EntityFunctions.TruncateTime(EndDate))
                   select c);



With the truncate time i get following error

LINQ to Entities does not recognize the method 'System.Nullable`1[System.DateTime] TruncateTime(System.Nullable`1[System.DateTime])' method, and this method cannot be translated into a store expression<br />


thanks in advance for any help.

解决方案

You could build your query by using lambda expression like in the next example and should work:

var Transaction = context.JobCards.Where(c => EntityFunctions.TruncateTime(c.TransDateRequired) > EntityFunctions.TruncateTime(FromDate)) && (EntityFunctions.TruncateTime(c.TransDateRequired) < EntityFunctions.TruncateTime(EndDate)));


Try this:

//Since date columns accepts null in your db table
//Make it nullable
DateTime ?FromDate =  DateTime.Now;
 
DateTime ?EndDate = DateTime.Now;

var Transaction = (from c in context.JobCards 
                                    where (c.TransDateRequired >= FromDate 
                                        && 
                                    c.TransDateAdded <= EndDate)
                                    select c).ToList();


--Amy


What ive done is formatted selection dateandtime so that time is always 12:00 AM,

Now on date from it will use selected date and enddate it will use date +1 day up to 12:00 AM.

so selecetion will only be date between selections.

Thanks for help and suggestions


这篇关于在所选日期内查找交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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