c# - Using DateTime in Dynamic LINQ to Entities -


i using linq entities retrieve item purchase dates follows:

where entityfunctions.truncatetime(order.purchasedate) == mypurchasedate.date 

the key here db column contains date , time time must stripped compare. code works fine.

now, want same thing using dynamic linq entities. using dynamic.cs vs2010 code samples folder. when code:

.where("entityfunctions.truncatetime(purchasedate) == @0", mypurchasedate.date); 

or variant of same error message. have code string value make work? (since can use .startswith or .contains inside string hoping there date function dynamic linq recognize).

i know can create dynamic linq query date range, conceptually:

purchasedate >= mypurchasedate@midnight , purchasedate <= mypurchasedate+23:59:59 

in fact, maybe date range more efficient sql server perspective know if truncatetime or toshortdate exists within dynamic linq entities.

i started using dynamic linq project , wanted compare dates without time component. microsoft's dynamic linq c# sample code (dynamic.cs) supports fixed set of types, , entityfunctions isn't 1 of them.

but little experimentation, found adding entityfunctions array of predefined types enables use of truncatetime , other entityfunctions methods too.

here's dynamic.cs predefinedtypes array looks in project:

static readonly type[] predefinedtypes = {     typeof(object),     typeof(boolean),     typeof(char),     typeof(string),     typeof(sbyte),     typeof(byte),     typeof(int16),     typeof(uint16),     typeof(int32),     typeof(uint32),     typeof(int64),     typeof(uint64),     typeof(single),     typeof(double),     typeof(decimal),     typeof(datetime),     typeof(timespan),     typeof(guid),     typeof(math),     typeof(convert),     typeof(system.data.objects.entityfunctions)             // jimm }; 

with modified dynamic.cs file, i'm able create dynamic linq queries including expressions purchasedate example in question.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -