New Posts New Posts RSS Feed: compare DateTime object in .where()
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

compare DateTime object in .where()

 Post Reply Post Reply
Author
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Topic: compare DateTime object in .where()
    Posted: 29-Jul-2009 at 11:33pm
I want to compare DateTime property amount entities, but I don't know how to write the condition to use fill the where(). this is the line of code which can stands for what I want, but it's wrong syntax:

var query = AdditionalFunctions.manager.Dinvoices.Where(DateTime.Compare(o =>o.DATE, fromDateEdit.DateTime));

because DateTime object must be compared by DateTime.Compare(dateTime1, dateTime2) method, but how can I fit DateTime.Compare(dateTime1, dateTime2) into .Where()? 
Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post Posted: 30-Jul-2009 at 3:00pm
DateTime.Compare(t1, t2) returns a signed number indicating the relative values of t1 and t2:

<0 means t1 is earlier than t2
0 means t1 is same as t2
>0 means t1 is later than t2

Therefore, if checking for equality for example, your query should look like:

var query = AdditionalFunctions.manager.Dinvoices.Where(o => DateTime.Compare(o.DATE, fromDateEdit.DateTime) == 0);

Edited by eileenv - 30-Jul-2009 at 3:01pm
Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 30-Jul-2009 at 5:20pm
Thanks eileenv, it works

Secondly, I want to add a 'for' loop inside of 'where()', is that possible?

what i mean is, if i have a list of conditions and the amount of conditions is changing as well, so i need a for loop inside of 'where' to go through each condition of that list, is that possible?

for instance:
 var query = AdditionalFunctions.manager.Dinvoices.Where(o=> for(int i=0;i<conditions.count;i++){o.Type == conditions})

the reason i use a for loop is, the amount of conditions is changing, in this case I can't set each condition into 'where' without 'for' loop. i want to select all data from DB into a query and then use for loop, but because our data storage is too big, if we don't put condition to make a query, the 'var query' won't take so much data and the system will be pop up a error message as well.



Back to Top
eileenv View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 15-Jun-2007
Location: United States
Posts: 68
Post Options Post Options   Quote eileenv Quote  Post ReplyReply Direct Link To This Post Posted: 05-Aug-2009 at 2:26pm

As much as we'd love to answer every question on our forum, the support team at IdeaBlade must limit themselves to those that are related specifically to DevForce. If there is a specific question you have such as "How does this DevForce feature work?", we'd be more than happy to respond. However, for general programming questions, we simply cannot take the time or responsibility to answer them. There are plenty of resources on the web on how to use LINQ and extension methods. Perhaps someone from the general public can supply a ready answer.

We hope you understand.

IdeaBlade Support

Back to Top
monkeyking View Drop Down
Groupie
Groupie
Avatar

Joined: 04-Mar-2009
Location: brisbane
Posts: 68
Post Options Post Options   Quote monkeyking Quote  Post ReplyReply Direct Link To This Post Posted: 05-Aug-2009 at 6:55pm
i resolved , thx
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down