Multiple Parameters for Filtered in the Business List

Multiple Parameters for Filtered in the Business List

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


sutono posted on Wednesday, December 29, 2010

Hi Experts,

i'm a newbie on CSLA.Net Framework.

Currently i'm working on a project using CSLA.Net Framework, and for data access i'm using LinQ to SQL.

for example i have a Business List for Student. (CourseList)

my question is :

1. From this object, how do i add several parameters?
2. Multiple set of criteria e.g. search by FirstName and DOB /  Just search by ID

cause when i'm adding 2 parameters on DataPortal.Fetch (Factory Method) it showed error

"No Overload for method 'Fetch' takes '2' arguments"

 

So do i need to create a complex criteria if i'd like to filter several parameters in this BusinessList ?

can somebody provide me the code....?

 

Thx

JonnyBee replied on Wednesday, December 29, 2010

1. You should create a complex object that inherits from CriteriaBase and use managed properties. Example

    [Serializable]
    public class CreateCriteria : CriteriaBase
    {
      public static readonly PropertyInfo<Guid> ProjectIdProperty = RegisterProperty<CreateCriteria, Guid>(p => p.ProjectId);
      public Guid ProjectId
      {
        get { return ReadProperty(ProjectIdProperty); }
        set { LoadProperty(ProjectIdProperty, value); }
      }

      public static readonly PropertyInfo<int> RoleProperty = RegisterProperty<CreateCriteria, int>(p => p.Role);
      public int Role
      {
        get { return ReadProperty(RoleProperty); }
        set { LoadProperty(RoleProperty, value); }
      }
    }

2. Multiple sets of criterias can be cumbersome. Out-of-the-box - you will have to create separate sets of LINQ queries. Or download and use LinqKit from Joe and Ben albahari, http://www.albahari.com/nutshell/linqkit.aspx , and use the PredicateBuilder to build dynamic where statements in LINQ.

sutono replied on Wednesday, December 29, 2010

Hi JonnyBee,

thanks for your quick reply...

do mean that i have to use combining expressions on LINQKit, by calling invoke and expand methods?

or maybe i rather should ask that what is your best recommended for my problem?

JonnyBee replied on Wednesday, December 29, 2010

Hi,

1. In order to send multiple parameters to the fetch method you should create a CriteriaObject.

2. LINQKit's PredicateBuilder will help you create dynamic where statements in your data access. Read this article:
    http://www.albahari.com/nutshell/predicatebuilder.aspx

I'd also recommend LinqPad for testing your queries. You can add a reference to your EF or L2S objects assembly - add LinqKit (or other assemblies) and write dynamic queries on your own data access assembly. You can also watch the video tutorials here: http://oreilly.com/pub/e/1295

sutono replied on Sunday, January 02, 2011

Hi JonnyBee..

thx for your reply... its a wonderful source for me Smile

thx a lot.. i've tried and it works... thumb up for you  Big Smile

 

once again thanks...,

Stone

Copyright (c) Marimer LLC