c# - how to get the records between specific time in entity framework -


i want fetch records between 7am , 3pm . how write linq query same?

code

 var items = pirs.where(a => !a.dataframe.endswith("aaaaaaaaaaa=") && (fromdate == null || fromdate.value.date <= timezoneinfo.converttimefromutc(convert.todatetime(a.timestamp), timezoneinfo.findsystemtimezonebyid("india standard time")).date) && (todate == null || todate.value.date >= timezoneinfo.converttimefromutc(convert.todatetime(a.timestamp), timezoneinfo.findsystemtimezonebyid("india standard time")).date) && (a.timestamp.hour > 7 || a.timestamp.hour < 15))                .groupby(a => a.dataframe.substring(a.dataframe.length - 12))                .select(g => g.first()).orderby(a => a.timestamp); 

sample data

timestamp   "2017-07-21t14:06:02.203z" 

the way question written, difficult understand you're asking, give general way of achieving (i think) want.

say have class, foo:

class foo {     public datetime date { get; set; } } 

given list<foo>, can instances of foo in list who's date property between hours so:

var mylist = new list<foo>(); int starthour = 7; // 7am int endhour = 15; // 3pm var result = mylist.where(item => item.date.hour >= starthour && item.date.hour <= endhour); 

the result enumerations contains items in mylist whos date property's hour field between starthour , endhour inclusive.

something note, could use extension method simplify this:

public static bool between(datetime input, int x, int y) {     return (input.hour => x && input.hour <= y); }  var result = mylist.where(item => item.date.between(7, 15)); 

however, mentioned using entity framework, second solution incompatible with, since when query dbset, operation isn't performed program, translated sql ef , executed db provider instead. using extension method in query require loading memory first, not recommend.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -