You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@austindrenski, in addition to all the great translations you've recently added, I think we're missing one: IPAddress.Parse(), which is basically the way to specify an IP address literal...
I ran into some trouble along the way with EF Core preempting the translators by transforming the .Parse(string) calls and replacing IPAddress.Parse('127.0.0.1') with @__Parse_0 (value: '127.0.0.1').
I got around this by modifying NpgsqlEvaluatableExpressionFilter, but I'm not sure that I fully understand what this class is meant to do. Obviously it marks methods that are not evaluable, but there are many methods for which we don't use this class, and which we don't have the problem described above.
The action seems to be happening in in ParameterExtractingExpressionVisitor which is called from QueryModelGenerator. It replaces the entire call (IPAddress.Parse("127.0.0.1")) with a parameter whose value is just a constant ('127.0.0.1').
@roji Do you have any insight into how this part of the EF Core pipeline is supposed to work?
NpgsqlEvaluatableExpressionFilter is only meant to specify methods that should not be evaluated on the client, ever. This is a way to avoid evaluating things like DateTime.Now client-side (because time zones may be different), or creating a new GUID client-side (which EF Core would reuse across different database rows, rather than generating a GUID per-row). If you're interested in reading more about this, see the discussion in dotnet/efcore#12552 (comment) (including possible upcoming changes).
For our purposes... if the expression contains IPAddress.Parse("127.0.0.1") (with a constant!), then it does make sense for EF Core to evaluate it locally and send the result as a parameter (this is exactly what NpgsqlEvaluatableExpressionFilter is meant to prevent) - there's no reason to avoid it. The only important bit is to make sure that the parameter really does contain the proper instance of IPAddress - it's not clear from your comments if that's happening or not.
If, however, the expression contains a non-constant (e.g. some text column in the database, or a C# variable), then EF Core cannot do client evaluation as above, and you translator should get invoked as expected. Here are some examples:
vartext="127.0.0.1";// With variablevarblogs=ctx.Blogs.Where(b =>b.SomeIp==IPAddress.Parse(text)).ToList();// With database columnvarblogs=ctx.Blogs.Where(b =>b.SomeIp==IPAddress.Parse(b.SomeTextColumn)).ToList();
So what you're seeing is probably simply the expected correct behavior, let me know if otherwise.
Activity
austindrenski commentedon Jul 22, 2018
Sure! Should I include
PhysicalAddress.Parse()at the same time?[-]Translate IPAddress.Parse()[/-][+]Translate {IPAddress,NetworkAddress}.Parse()[/+]roji commentedon Jul 22, 2018
Absolutely!
austindrenski commentedon Jul 22, 2018
See #535 for implementations + tests.
I ran into some trouble along the way with EF Core preempting the translators by transforming the
.Parse(string)calls and replacingIPAddress.Parse('127.0.0.1')with@__Parse_0(value:'127.0.0.1').I got around this by modifying
NpgsqlEvaluatableExpressionFilter, but I'm not sure that I fully understand what this class is meant to do. Obviously it marks methods that are not evaluable, but there are many methods for which we don't use this class, and which we don't have the problem described above.The action seems to be happening in in
ParameterExtractingExpressionVisitorwhich is called fromQueryModelGenerator. It replaces the entire call (IPAddress.Parse("127.0.0.1")) with a parameter whose value is just a constant ('127.0.0.1').@roji Do you have any insight into how this part of the EF Core pipeline is supposed to work?
roji commentedon Jul 23, 2018
NpgsqlEvaluatableExpressionFilteris only meant to specify methods that should not be evaluated on the client, ever. This is a way to avoid evaluating things likeDateTime.Nowclient-side (because time zones may be different), or creating a new GUID client-side (which EF Core would reuse across different database rows, rather than generating a GUID per-row). If you're interested in reading more about this, see the discussion in dotnet/efcore#12552 (comment) (including possible upcoming changes).For our purposes... if the expression contains
IPAddress.Parse("127.0.0.1")(with a constant!), then it does make sense for EF Core to evaluate it locally and send the result as a parameter (this is exactly whatNpgsqlEvaluatableExpressionFilteris meant to prevent) - there's no reason to avoid it. The only important bit is to make sure that the parameter really does contain the proper instance ofIPAddress- it's not clear from your comments if that's happening or not.If, however, the expression contains a non-constant (e.g. some text column in the database, or a C# variable), then EF Core cannot do client evaluation as above, and you translator should get invoked as expected. Here are some examples:
So what you're seeing is probably simply the expected correct behavior, let me know if otherwise.
austindrenski commentedon Jul 23, 2018
Ahhh. That all makes sense. I saw some unexpected parameterization and
panickedassumed the worst!What's interesting (and caught me off-guard) is that both of the following are parameterized:
Much appreciated!