efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF.Functions.Like Extension

Open ralmsdeveloper opened this issue 9 years ago • 5 comments

Do you have plans to implement "EF.Functions.Like" as an extension?

I know I could create this, but I would like to see this native!

is a humble suggestion for the staff.

And to say that all of you are to be congratulated, for what you have promised and fulfilled!

ctx .Posts.Where(x => x.Title.Like(“%NET%”)).ToList();

ralmsdeveloper avatar Sep 23 '17 13:09 ralmsdeveloper

Isn't Title.Contains enough, at least for your example? Or you would like to use all LIKE capabilities?

Kurira avatar Sep 23 '17 17:09 Kurira

@ralmsdeveloper In the past we have avoided creating such extension methods over common types because it can become very confusing when they show up outside of the context of EF Core LINQ queries. In EF Core however, we have included an in-memory implementation for Like(), so this argument loses some of its power.

BTW, Like() is already an extension method, but over the DbFunctions instance in EF.Functions. A Like() extension method over string would be a new method.

For sure we will discuss this in triage and it would be good if we get additional feedback from the community.

Personally I think that a Like() extension method over string that you get if you add EF Core as a dependency, is not completely unreasonable, even if the in-memory implementation may be relatively costly. However, I am not convinced there is much value in it, and I like how having it hanging from EF.Functions makes it both discoverable and explicit that it comes from EF.

divega avatar Sep 23 '17 19:09 divega

@Divega understand your line of reasoning, the intention was to have a Like of a String extension on a dependency of the DbFunctions.

Even so thank you, as I said was a suggestion, which I think is valid!

ralmsdeveloper avatar Sep 24 '17 23:09 ralmsdeveloper

@ralmsdeveloper We discussed this in triage and decided that we will not go down the path of making these extension methods on common types. While, as @divega pointed out, this may now work, it is not the intention that these methods be used anywhere and it would encourage their use in arbitrary places, sometimes without the developer even knowing that they are using EF functionality.

ajcvickers avatar Sep 25 '17 19:09 ajcvickers

All right, you guys are doing a great job :)

ralmsdeveloper avatar Sep 25 '17 20:09 ralmsdeveloper