How to do Where-statement with Date operations in QuerySpec

Posts   
 
    
omborddata
User
Posts: 42
Joined: 18-Apr-2012
# Posted on: 08-Nov-2013 14:14:03   

Hi!

I have a table in my Sql Server called Crew. Every crew has as BirthDate field. Which is a date field. I want to get all crew that for example is born on November.

I've tried this but get an error.

Dim whereStatement As SD.LLBLGen.Pro.ORMSupportClasses.IPredicate Dim birthDateMonth As Integer = 11 whereStatement = Month(CrewFields.BirthDate) = birthDateMonth

Exception: Value of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField2' cannot be converted to 'Date'.

How do I do this? I've found this page in the documentation about function mappings and calls, thought I could use those functions in my queryspec:

http://www.llblgen.com/documentation/4.0/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/QuerySpec/gencode_queryspec_functionmappings.htm

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 09-Nov-2013 06:36:19   

The Month on your example uses the .net framework function. You must use DateTimeFunctions mapping class. Example:

var qf = new QueryFactory();
var q = qf.Order.Where(DateTimeFunctions.Month(OrderFields.OrderDate).Equal(4));
var results = adapter.FetchQuery(q);
David Elizondo | LLBLGen Support Team
omborddata
User
Posts: 42
Joined: 18-Apr-2012
# Posted on: 15-Nov-2013 18:06:47   

Ok, thanks!