enisn / AutoFilterer

AutoFilterer is a mini filtering framework library for dotnet. The main purpose of the library is to generate LINQ expressions for Entities over DTOs automatically. The first aim is to be compatible with Open API 3.0 Specifications
MIT License
458 stars 37 forks source link

✨ Introduce multiple CompareTo attribute with IFilterableType #28

Closed enisn closed 3 years ago

enisn commented 3 years ago

Introduce Multiple CompareTo Attribute

CompareTo attribute can be placed more than once over a property. Also you can pass a ÌFilterableType type parameter to define which comparison should be applied.

Example

You can do something like that:

public class MultipleTypeCompareToAndComparisonFilter : FilterBase
{
    [CompareTo(typeof(ToLowerContainsComparisonAttribute), nameof(Book.Title))]
    [CompareTo(typeof(EndsWithAttribute), nameof(Book.Author), CombineWith = CombineType.And)]
    public string Search { get; set; }

    public class EndsWithAttribute : StringFilterOptionsAttribute
    {
        public EndsWithAttribute() : base(StringFilterOption.EndsWith, StringComparison.InvariantCultureIgnoreCase)
        {
        }
    }
}

This query will create something like that:

db.Books.Where(x =>
                    x.Title.ToLower().Contains(filter.Search.ToLower())
                    && x.Author.EndsWith(filter.Search, StringComparison.InvariantCultureIgnoreCase));
enisn commented 3 years ago

Documentation is missing