Extended Search Aspect
This aspect requires CodeFluent Entities build 774.
And the following method will be generated:
public static CustomerCollection Search(string fullName, System.DateTime dateOfBirth)
The function used to filter rows (Equals, Contains, StartsWith, etc.) is not dynamic: FullName will use the Equals or StartsWith functions depending of your configuration and DateOfBirth will use Equals function.
As its name implies, the extended search aspect extends these features. After registering the aspect in your project, you can configure the method to use dynamic filtering functions:
Now the generated method looks like:
public static CustomerCollection Search( string fullName, FilterFunctions fullNameFilterFunction, System.DateTime dateOfBirth, FilterFunctions dateOfBirthFilterFunction)
The aspect automatically create new parameters that allow to specify the function to use for each search parameter. FilterFunctions enumeration defines commonly used filters:
- Not equals,
- Starts with,
- Ends with,
- Is less than,
- Is less than or equal to,
- Is greater than,
- Is greater than or equals to,
- Not contains,
- Contains (Full-text),
- Not contains (Full-text),
- Contains (FreeText),
- Not contains (FreeText)
Here’s an example:
CustomerCollection.Search( "John", FilterFunctions.Contains, new DateTime(2014, 1, 1), FilterFunctions.IsLessThanOrEqualTo);
This enumeration can be multi-valued (optional). In this case you can combine functions, but the generated stored procedure is more complex so use it only when needed.
CustomerCollection.Search( "John", FilterFunctions.Contains | FilterFunctions.IsLessThan, new DateTime(2014, 1, 1), FilterFunctions.IsLessThanOrEqualTo);
You can also specify which functions should be supported:
Now we’re going to register the aspect in our solution. First, copy the SoftFluent.Samples.ExtendedSeach.Aspect project in your solution.
Then, add a reference in the model to the aspect project:
And select the ExtendedSearch aspect:
Finally, build your model! Search methods now have new parameters J.
With the power of CodeFluent Entities and a few lines of code, we have added the possibility to extend search method of our choice. Of course this aspect 100% reusable across all your projects. Can you do that without CodeFluent Entities?
The code is available on our GitHub repository: https://github.com/SoftFluent/CodeFluent-Entities/tree/master/Extensions/SoftFluent.ExtendedSearch
The R&D Team