Advantages of using criteria objects in v4?

Advantages of using criteria objects in v4?

Old forum URL: forums.lhotka.net/forums/t/8965.aspx


c_manboy posted on Thursday, May 20, 2010

I decided to use v4 for a project and am curious if there's any advantage in using a custom criteria object to pass multiple values in the DataPortal.Fetch method as opposed to passing them as a param array?

RockfordLhotka replied on Thursday, May 20, 2010

No, if you are passing a single, serializable/primitive value then there's no value in having your own criteria class.

c_manboy replied on Thursday, May 20, 2010

Rocky, thanks for csla, writing a great book, and supporting us newbies on your forums.  I really appreciate it.

tiago replied on Saturday, May 22, 2010

Hi Rocky,

I was under the impression that for CSLA.NET 4 a Criteria class was no longer needed. Re-reading "CSLA 4 data portal changes" on your blog you say "It is now possible to use any serializable object as a criteria."

[pedantic mode on]

When you say "a criteria" it looks like you mean "one criteria". But then again "criteria" is plural so one should say "one criterion" or "a criterion". 

[pedantic mode off]

Entering the no jokes mode, the point is: when do we need to use a Criteria class?

a) when we need to pass a non primitive type?

b) when we need to pass more than one type?

RockfordLhotka replied on Saturday, May 22, 2010

That is correct, you need a criteria class when

  1. you need to pass a non-primitive and otherwise non-serializable type
  2. you need to pass more than one value

I thought about extending the data portal calls to accept params arrays, like I do with the child data portal. But there are problems with using params that many people have encountered with the child data portal, and I don't know how to solve them. The problems are edge cases, but they do occur, and I decided I didn't want to introduce that issue to the top-level data portal without a solution.

So you can pass any one serializable or primitive value as criteria in CSLA 4. Of course your serializable value can be a custom criteria (or any other business type), so the flexibility is very high.

pecen replied on Friday, December 28, 2012

Hi,

Picking up on this thread and hope you could clarify one thing.

You say that you need a criteria class when: "1. You need to pass a non-primitive type". Is that true for strings as well, since strings are not a primitive type.

Regards

Peter Centellini

JonnyBee replied on Friday, December 28, 2012

String work just fine - no need for a criteria object when the criteria is one string value..

"you need to pass a non-primitive and otherwise non-serializable type"

For CSLA 4.x you should regard SingleCriteria as obsolete - you normally only need a criteria object when

Copyright (c) Marimer LLC