Comments (5)
Hello, Thank you for this update!
I have tried the second example using Guid's instead of integer's and I get the following error:
System.InvalidOperationException : No coercion operator is defined between types 'System.Guid' and 'System.Collections.Generic.List`1[System.Guid]'.
from gridify.
I created a simple test project and it worked as expected, 🤔 ... maybe you forgot to update to the latest version. v2.13.1
?
GridifyGlobalConfiguration.CustomOperators.Register<GuidInOperator>();
var targetGuid = Guid.NewGuid();
var repo = new List<TestTask>()
{
new() { State = targetGuid },
new() { State = Guid.NewGuid() },
new() { State = Guid.NewGuid() },
new() { State = Guid.NewGuid() },
}.AsQueryable();
var ids = new List<Guid> { Guid.NewGuid(), targetGuid, Guid.NewGuid() };
var expected = repo.Where(x => ids.Contains(x.State)).ToList();
// act
var actual = new QueryBuilder<TestTask>()
.AddMap("state", q => q.State,
value => value.Split(";", StringSplitOptions.RemoveEmptyEntries).Select(Guid.Parse).ToList())
.AddCondition($"state #In {Guid.NewGuid()};{Guid.NewGuid()};{targetGuid}")
.Build(repo)
.ToList();
Debug.Assert(actual.Count == 1);
actual.Dump();
class GuidInOperator : IGridifyOperator
{
public string GetOperator()
{
return "#In";
}
public Expression<OperatorParameter> OperatorHandler()
{
return (prop, value) => ((List<Guid>)value).Contains((Guid)prop);
}
}
internal class TestTask
{
public Guid State { get; set; }
}
from gridify.
Apologises I made a very silly mistake, couldn't see the wood for the tree. Works a treat, thank you very much!
from gridify.
in v2.13.1
, Custom operators can support type casting so now it is possible to create an In
operator if needed.
e.g:
class InOperator: IGridifyOperator
{
public string GetOperator()
{
return "#In";
}
public Expression<OperatorParameter> OperatorHandler()
{
return (prop, value) => value.ToString()
.Split(";",StringSplitOptions.RemoveEmptyEntries)
.Contains(prop.ToString());
}
}
Or if you need to only support a specific type you can parse it using GridifyMapper's third overload, which is value converter:
e.g for int:
var fitler = "state#In2;4;6";
// Here we are converting the value to a List<int>
mapper.AddMap("state", q => q.State, value => value.Split(";").Select(int.Parse).ToList())
internal class IntInOperator : IGridifyOperator
{
public string GetOperator()
{
return "#In";
}
public Expression<OperatorParameter> OperatorHandler()
{
return (prop, value) => ((List<int>)value).Contains((int)prop);
}
}
from gridify.
hi @sjblack,
Oh weird! can you share your operator?
from gridify.
Related Issues (20)
- RobiniaDocs API Explorer HOT 1
- Filtering on Double with different culture HOT 9
- Possibility to use Gridify (as parser) to create your own non-LINQ query builder HOT 2
- add support automatic mapping generation for child classes HOT 1
- Update documentation site dependencies (Vuepress2)
- Gridify.Elasticsearch generate DSL query (non-generic) HOT 3
- JavaScript client library HOT 3
- Creating an Abstractions Layer for Gridify
- Error "Specified method is not supported" when querying the Nested List field in Elasticsearch HOT 2
- DateTime Kind and PostgreSQL HOT 13
- Support for. NET8 HOT 4
- NativeAOT support
- Why library can not resolve IGridifyMapper<T> default in DbContext.ServiceProvider if exists HOT 1
- GRPC Support HOT 2
- Comparing data between two fields rather than using hardcoded values
- Cleanup dependencies HOT 2
- Filtering based on IDictionary values
- Passing filter value on CustomOperator Expression creation - for ContainsAny operator HOT 10
- Support automatic mapping generation for list of primitives
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gridify.