Results 1 to 4 of 4

Thread: Reverse Filtering using link

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Reverse Filtering using link

    Hi All,

    I do an initial linq statement that in this scenario :

    Code:
    var locationBuilding = from location in locationBuildings.LocationBuildings select location;
    That returns a set of 11 address's

    Later, I attempt to filter to obtain a single address from this set using :

    Code:
    locationBuilding = from location in locationBuildings.LocationBuildings where location.LocationName.Contains(Row["RISKADDRESS"].ToString()) select location;
    In general this gives me the results I want. However, on occassions I need to reverse this search.

    i.e.

    my Row["RiskAddress"] contains the value: 32 my street, my town,
    but my set that I'm filtering on holds a value: 32 my street, my town

    So of course my filter returns 0 records because of the trailing comma, so in cases were the returning count is 0 I want to say return me the address from the list that is like Row["RiskAddress"].

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Reverse Filtering using link

    Should you maybe be doing this:
    Code:
    where location.LocationName.Contains(Row["RISKADDRESS"].ToString())
    the other way around? Or maybe you could include both, i.e. where A contains B or B contains A.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: Reverse Filtering using link

    That's what I'm currently doing, I want the reverse of it.

    because my Row["RISKADDRESS"] holds an extra comma on the end the contains isn't returning the address line from the list. So I want were RISKADDRESS contains 1 of the values from the list return the item in the list as opposed to where an item in the list contains RISKADDRESS.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Reverse Filtering using link

    So just switch them around. You've got A contains B. Make it B contains A and you're done.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width