-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add capability for utilizing "DbFunctions" #38
Comments
This feature is implemented. If users want this functionality I can prepare a PR here. The implementation complexity is hidden, and clean usage is provided. If you define following specification:
The evaluator will translate this automatically into
You can also provide separate/different search terms for each property. The
The evaluator will translate this into
|
I like it but am unsure about the searchGroup implementation. Why is it intuitive that Name and Address, belonging to group 1, are OR'd together while Phone is ANDed with them since it's a different group? I'm not sure I have a better syntax but we should think about it more perhaps. Possible options:
|
The actual numbers don't hold any importance. Whatever number, it just has to be the same within the group. Then, any group will OR within itself. I added this in the last minute, so it might not be the best syntax. Anyhow, we need some identifier for groups. This is how it is evaluated afterward:
The
You will need the parameter replacer as well.
|
Ok, @ardalis pointed out something to me, and I had to crosscheck this. In the previous EF versions, if you wanted to query some substring in a given column, and if you do it in the following way
then, the EF was not able to translate this correctly, and the search was done in memory after the data has been retrieved from DB. But, in EF Core 3, it seems this behaviour is changed, and EF can evaluate much more complex expressions now. So, the expression will be translated into the following SQL query exec sp_executesql N'SELECT [c].[Id], [c].[Address], [c].[Email], [c].[Name]
FROM [Customer] AS [c]
WHERE (@__filter_Address_0 = N'''') OR (CHARINDEX(@__filter_Address_0, [c].[Address]) > 0)'
,N'@__filter_Address_0 nvarchar(4000)',@__filter_Address_0=N'mer2' On the other hand, if you utilize the EF DbFunctions, this is what you get
SELECT [c].[Id], [c].[Address], [c].[Email], [c].[Name]
FROM [Customer] AS [c]
WHERE [c].[Address] LIKE N'%mer2%' As a conclusion, if you want to query a substring, then you might use "Contains" as well. The new |
So should we leave in the Search or roll it back and just rely on .Contains? Do we need to do some perf analysis to know for sure? |
Actualy, they produce quite different results.
If we wanna find something by substring, then indeed these functionalities will overlap. But, that's where the similarities end. Since we already have it, I'd say let's keep it. If you have a reason why not, we can rollback. PS. I have done this analysis in the past, can't remember exactly the details (should have blogged). At one point |
Ok, sounds good. |
Done. |
I wanted this feature for quite some time. I want to utilize DbFunctions (e.g. Like) through specifications somehow. In production not rarely we need "Like" queries. It offers some quasi full-text search. Not applicable everywhere, but there are cases where it's quite useful.
The idea is to have the following usage. In specification, we should have the capability to define what we want to search for:
And once you have those information stored somehow, it should be utilized into something as below
The way how DbFunctions are parsed internally in EF, makes it really tricky to implement this. Also, if you noticed, you should use the "x" of Where's Func argument (not just provide expression in Like), otherwise won't be parsed correctly. I tried to implement this, and it includes complete expression reconstruction, a lot of reflection.. and shortly said, I failed badly :)
I do believe someone can come up with much brighter idea, and you're more than welcome to do so.
The text was updated successfully, but these errors were encountered: