CSLA .NET

Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum


CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • How to match part of a string?

    rated by 0 users
    Answered (Not Verified) This post has 0 verified answers | 5 Replies | 1 Follower

    Not Ranked
    13 Posts
    mtrtm posted on Mon, Oct 22 2012 11:25 AM

    Hi all,

    This seems like a very simple question, but searching for 'like' isn't very helpful and searching wildcards for csla isn't coming up with any usable results.

    Basically, I would like to get business objects back that partially match a search term. For instance, if a user enters 'matt' I want results to include 'matt' and 'matthew'.  Is there an easy way to do this via criteria or any other easy trick to denote a 'like' or 'wildcard' match on a string field that I am overlooking? 

    All Replies

    Top 25 Contributor
    243 Posts
    Curelom replied on Mon, Oct 22 2012 11:59 AM

    MyProperty.Contains("mysearchstring")

    Not Ranked
    13 Posts
    mtrtm replied on Mon, Oct 22 2012 12:33 PM

    Hi Curelom - sorry, I should have been a bit more explicit.  Here is my code:

     

     

    PeopleCriteria fetchCriteria = new PeopleCriteria();

    fetchCriteria.Name = nameToSearchFor;

     

    DataPortal<People> dp = new DataPortal<People>();

    dp.FetchCompleted += UpdateSearchResults_FetchCompleted;

    dp.BeginFetch(fetchCriteria);

     

     

    You will notice the second line I am setting the name to whatever I want to search for. But using the criteria like that translates into equality. Is there any way in the criteria to specify that, instead of doing an equals, I want to do a like for that particular field?  We need the ability to do either/or, so it's not like I can just switch to always doing a .Contains in the fetch method.  

    Top 25 Contributor
    243 Posts

    Could you show your DataPortal Fetch method?

    Top 10 Contributor
    2,279 Posts
    Suggested by JonnyBee

    Hi,

    Add more properties to your criteria object to instruct which type of search to perform i DataPortal_Fetch

    Jonny Bekkum, Norway CslaContrib Coordinator

    Not Ranked
    13 Posts
    mtrtm replied on Wed, Oct 24 2012 1:42 PM

    Hi Jonny,

    Thanks again for the answer - very simple and straightforward. I just added the property and the following line, and now in my fetch I can differentiate between equals and like.

    fetchCriteria.MatchPartialName = true;

    Page 1 of 1 (6 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems