CriteriaBase as Generic Question

CriteriaBase as Generic Question

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


lee_b posted on Thursday, August 26, 2010

Hi,

 

I have just updated my CSLA version from 4.0.0.-100201 to 4.0.0.-100723 and have developed quite a few errors from this.

My first error is around the changing of CriteriaBase to a generic.

Previously my class was:

pubic class UserListCriteria<T> : CriteriaBase
{

public UserListCriteria() : base (typeof(T))
{ }

public UserListCriteria(int id) : base (typeof(T))
{

Id = id;

}

public UserListCriteria(string username) : base (typeof(T))
{

UserName = username;

}

public int Id {get; set;}
public string UserName {get; set;}

}

Where the Criteria is referenced by:
Csla.DataPortal.Fetch<User>(new UserListCriteria<User>( int | string ));

This gives "Using the generic type 'Csla.CriteriaBase<T> requires 1 type arguments"

Should I change my Class definition to

pubic class UserListCriteria : CriteriaBase<UserListCriteria>  [seems the obvious one to me, but...]

or

pubic class UserListCriteria : CriteriaBase<User>

or

pubic class UserListCriteria<T> : CriteriaBase<UserListCriteria<T>>

 

 

Regardless of these changes, I get

Csla.CriteraBase<object> does not contain a constructor that takes one argument.

I realise that this is from the call to ' base(typeof(T))'. I assume this is no longer relevant since CriteriaBase is now a generic. Should I keep the  ' base()' call, or is that now redundant.

 

Sorry if this has been covered before, but I couldn't find any mentions around this.

 

RockfordLhotka replied on Thursday, August 26, 2010

You shouldn't be surprised by lots of changes from February to July - you were using essentially a preview/prototype version that evolved quite a lot over those months...

CriteriaBase (and some other base classes) now work like BusinessBase or ReadOnlyBase. They do this so you can use managed properties like in ReadOnlyBase, which makes these types much, much easier to use in Silverlight or WP7.

So:

public class CustomCriteria : CriteriaBase<CustomCriteria>

But you should also know that for single serializable values you don't need a formal criteria class at all anymore. So you only need a criteria class if your criteria consists of multiple values. And technically even then you don't need to use CriteriaBase (though that's easiest probably), as long as your type is serializable.

lee_b replied on Thursday, August 26, 2010

Thank you again Smile

JJLoubser replied on Tuesday, November 30, 2010

thank you guysSmile

Copyright (c) Marimer LLC