Home > Aspects > Extended Search Aspect

Extended Search Aspect

This aspect requires CodeFluent Entities build 774.

Third-party component providers such as Infragistics, Telerik or DevExpress, often provide data-grid with advanced filtering options:

CodeFluent Entities allows to generate Search methods by using CodeFluent Query Language (CFQL). For instance, searching for customers by name and date of birth can be done as so:

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:

Here’s an example:

 "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.

 "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

Happy coding,

The R&D Team

Categories: Aspects Tags: , ,
  1. Peter de Bruijn
    August 25, 2014 at 8:38 am

    Pretty neat functionality! Thx!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s