CodeSmith Community
Your Code. Your Way. Faster!

Question on TList Filter functionality

Latest post 07-03-2008 5:11 PM by rhettc. 4 replies.
  • 10-12-2006 7:35 AM

    Question on TList Filter functionality

    Hi,

     I'm new to .nettiers (amazing bit of kit by the way) and am having some problems with the Filter functionality of the TList:

     - A number of tables in the DB i'm working on have start and endDate fields - basically nothing is ever physically deleted, but rather logically deleted by populating the endDate field

    - I use the .GetAll() method to get everything back into tht TList collection for a given entity

     - I want to filter the collection using the following criteria string "EndDate = Null"

    - This works fine unless the endDate is not null, in which case the method IsOK (private bool IsOk(object ObjectPropertyValue , string Operator, string UserValue)) trys to cast the UserValue (Null) to a datetime....which is not going to happen so I get an exception!

    I realise that there are a number of alternatives (custom stored proc that returns all rows "where endDate is null" being the easiest I suspect), but don't want to go and do something bespoke whilst the functionality is already there in .nettiers.

    Thanks in advance

    Rich

    • Post Points: 45
  • 10-12-2006 12:31 PM In reply to

    Re: Question on TList Filter functionality

    Hi, you can do something like this.

    myList.ApplyFilter(delegate(MyEntity entity)
    {
            entity.EndDate == null;
    });

    .. do something with filtered list

    myList.RemoveFilter();

    More Info:
    http://wiki.nettiers.com/entitylayer

     


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    Filed under: ,
    • Post Points: 65
  • 10-17-2006 7:24 AM In reply to

    Re: Question on TList Filter functionality

    Thanks - works a treat!

    Rgds

    Rich

    • Post Points: 5
  • 06-06-2008 12:59 AM In reply to

    • xazos
    • Top 500 Contributor
    • Joined on 01-04-2007
    • Posts 9
    • Points 165

    Re: Question on TList Filter functionality

    Sorry to bring up a post from the dead but does anyone know how to do the above using VB.NET? I know VB.NET doesn't have anonymous methods but i thought someone might have a workaround. The normal .Filter property doesn't seem to be working for me at the moment.

     

    Cheers..

     

    Sam

    • Post Points: 35
  • 07-03-2008 5:11 PM In reply to

    • rhettc
    • Top 150 Contributor
    • Joined on 05-02-2007
    • Posts 28
    • Points 666

    Re: Question on TList Filter functionality

    You can do this in VB.  Your predicate doesn't have to be in-line. Modified something I had to make generic example for you.  Hope it helps.  The code this was based on was working but this code is untested. 

     

    Private Shared Function GetByFilter() As Entities.TList(Of Entities.Email)                           
    Dim predicate As System.Predicate(Of Entities.Email)                           Dim list As New Entities.TList(Of Entities.Email)                                         predicate = AddressOf IsMatchingEmail   

    list = YourCodeToFillTheList()

    list.ApplyFilter(predicate)                            Return list                     
    End Function                      Private Shared Function IsMatchingEmail(ByVal email As Entities.Email) As Boolean                          
    Return email.Email = "matchingAddress@filtering.com"                    
    End Function

     

    Filed under: , ,
    • Post Points: 5
Page 1 of 1 (5 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems