FindMatches issue

Posts   
 
    
Posts: 98
Joined: 09-Feb-2005
# Posted on: 19-Jun-2006 17:52:30   

Adapter, SQL 2k, June 9 beta

tbl_Lookup_Application

ApplicationID - Identity, int ParentApplicationID - int Name - nvarchar(200)

(ID, ParentID, Name)

15398   0       0 Application
15399   15398   0.0 Application
15400   15399   0.0.0 Application 
15401   15399   0.0.1 Application
15402   15399   0.0.2 Application
15403   15398   0.1 Application
15404   15403   0.1.0 Application
15405   15403   0.1.1 Application
15406   15403   0.1.2 Application
15407   0       1 Application
15408   15407   1.0 Application
15409   15408   1.0.0 Application
15410   15408   1.0.1 Application
15411   15408   1.0.2 Application
15412   15407   1.1 Application
15413   15412   1.1.0 Application
15414   15412   1.1.1 Application
15415   15412   1.1.2 Application

/// 
/// FetchAll_ApplicationCollection
/// 
EntityCollection<LookupApplicationEntity> _Application = new EntityCollection<LookupApplicationEntity>();

SortExpression sortExpression = new SortExpression(LookupApplicationFields.Name | SortOperator.Ascending);
_Application = new EntityCollection<LookupApplicationEntity>(new LookupApplicationEntityFactory());
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(_Application, null, 0, sortExpression);
}

// Set up hierarchy
Dictionary<int, LookupApplicationEntity> _dictionary = new Dictionary<int, LookupApplicationEntity>(_Application.Count);
foreach (LookupApplicationEntity _ApplicationItem in _Application)
    _dictionary.Add(_ApplicationItem.ApplicationId, _ApplicationItem);

foreach (LookupApplicationEntity _ApplicationItem in _Application)
{
    LookupApplicationEntity parent;
    _dictionary.TryGetValue((int)_ApplicationItem.ParentApplicationId, out parent);
    if (parent != null)
    {
        parent.ChildApplicationCollection.Add(_ApplicationItem);
        _ApplicationItem.ParentApplication = parent;
    }
}

/// 
/// Fetch_ApplicationCollection(MetadataCriteria mc)
/// 

EntityCollection<LookupApplicationEntity> filtered_Application =
    new EntityCollection<LookupApplicationEntity>(new LookupApplicationEntityFactory());


// Construct predicate
IPredicateExpression predicate = new PredicateExpression();
predicate.Add(LookupApplicationFields.Name % "1.%");

List<int> matching_Application = _Application.FindMatches(predicate);

Data:

The problem: This is some code I've consolidated that I'm using to lookup partial matches. (I realize that it's doing the filtering in .net instead of SQL. The data pulled in the app will rarely change, and so is cached, which I've removed from the code above.)

The problem is that FindMatches isn't returning anything. (I expect it to return 8 matches, every name that starts with '1.' If I set the Name to "0 Application", then I'll get a match, but if I set it to "1.1 Application", then I still won't get anything. I have tried things with and without the %'s.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 19-Jun-2006 18:18:38   

Interesting, I'll have a look. As you're using the June 9 beta, you're using the new code inside FieldLikePredicate to deal with non-regex patterns.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 09-Feb-2005
# Posted on: 19-Jun-2006 18:46:32   

Ah, ok well I didn't want to mention it because I wasn't 100% certain, but I'm almost certain that this was working with an earlier version. Not sure if that helps or not.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 20-Jun-2006 10:03:55   

Reproduced

Weird thing is: 1.% Application doesn't match anything, though 1% Application does. It's something with the regex that's being created.

(edit) haha oh my...


// replace all regex chars to escapes. 
StringBuilder patternCreator = new StringBuilder( _pattern );
patternCreator = patternCreator.Replace( ".", @"\." );
patternCreator = patternCreator.Replace( "$", @"\$" );
patternCreator = patternCreator.Replace( "^", @"\^" );
patternCreator = patternCreator.Replace( "{", @"\{" );
patternCreator = patternCreator.Replace( "[", @"\[" );
patternCreator = patternCreator.Replace( "(", @"\(" );
patternCreator = patternCreator.Replace( "|", @"\|" );
patternCreator = patternCreator.Replace( ")", @"\)" );
patternCreator = patternCreator.Replace( "*", @"\*" );
patternCreator = patternCreator.Replace( "+", @"\+" );
patternCreator = patternCreator.Replace( "?", @"\?" );
patternCreator = patternCreator.Replace( @"\", @"\\" );
string patternToUse = patternCreator.ToString();

Too funny... simple_smile (dear reader, can you spot my stupid mistake? wink )

Ok, fixed in next build simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Posts: 98
Joined: 09-Feb-2005
# Posted on: 20-Jun-2006 16:32:45   

heh heh. Human after all. I'll wait for the next build. Thanks.