Grouping and Filtering by DatePart

Posts   
 
    
VijayB
User
Posts: 8
Joined: 09-Mar-2005
# Posted on: 22-Mar-2005 14:53:32   

In MS SQL you can use the function DatePart to filter and group on datetime columns. For example if you wanted to groupby Qtr and Year from your datetime column you would just add: DatePart(yy,datetimeColumn) and DatePart(qq,datetimeColumn). Is there any way to add this function to a column for group by or filter in LLBLGen? If not what would be a better way to group and filter my data by quarters, years etc? Also would it be a waste of network traffic to send data by months and then group them on the client side?

Thanks,

Vijay Bala

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39861
Joined: 17-Aug-2003
# Posted on: 22-Mar-2005 15:25:06   

This is currently not supported.

Though you can work around this by adding a computed column to the table which reflects month(field) for example. Not ideal, but will do the trick.

Frans Bouma | Lead developer LLBLGen Pro
robpuk
User
Posts: 2
Joined: 15-Oct-2008
# Posted on: 16-Oct-2008 00:06:00   

Is filtering by month in a datetime column still unsupported in the latest version of LLBLGen?

I would like to be able to do something like:

predicateexpression.Add(entity.FieldName.Month == 5);

when loading a collection of entities using a GetMulti call.

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Oct-2008 05:37:23   

You can do it now (V2.0 or later) using DBFunctionCall:

// the collection to fetch
OrderCollection orders = new OrderCollection();

// build the filter
IPredicateExpression filter = new PredicateExpression();
EntityField month = OrderFields.OrderDate.SetExpression(
    new DbFunctionCall("MONTH", new object[]{OrderFields.OrderDate}));

filter.Add(month == 2);

// fetch results
orders.GetMulti(filter);

Or, using LINQ2LLBL (v2.6):

LinqMetaData metaData = new LinqMetaData();
var q = from o in metaData.Order
        where o.OrderDate.Value.Month == 2
        select o;

List<OrderEntity> orders = q.ToList();

Hope helpful wink

David Elizondo | LLBLGen Support Team
robpuk
User
Posts: 2
Joined: 15-Oct-2008
# Posted on: 16-Oct-2008 17:43:21   

Yes, that seems to solve the problem.

Thank you for your quick reply. simple_smile

Rob