question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Translate {IPAddress,NetworkAddress}.Parse()

See original GitHub issue

@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…

This should be pretty easy, feel like doing it?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Jul 23, 2018

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 https://github.com/aspnet/EntityFrameworkCore/issues/12552#issuecomment-405704458 (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:

var text = "127.0.0.1";
// With variable
var blogs = ctx.Blogs.Where(b => b.SomeIp == IPAddress.Parse(text)).ToList();
// With database column
var blogs = 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.

0reactions
austindrenskicommented, Jul 23, 2018

Ahhh. That all makes sense. I saw some unexpected parameterization and panicked assumed the worst!

What’s interesting (and caught me off-guard) is that both of the following are parameterized:

src.Where(x => x.Inet == IPAddress.Parse("127.0.0.1"));
// WHERE x."Inet" = @__Parse_0

string value = "127.0.0.1"
src.Where(x => x.Inet == IPAddress.Parse(value));
// WHERE x."Inet" = @__Parse_0

If you’re interested in reading more about this, see the discussion in aspnet/EntityFrameworkCore#12552 (comment) (including possible upcoming changes).

Much appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google Translate
Google's service, offered free of charge, instantly translates words, phrases, and web pages between English and over 100 other languages.
Read more >
IPAddress.Parse Method (System.Net)
Converts an IP address string to an IPAddress instance.
Read more >
Translation | Django documentation
Specify a translation string by using the function gettext() . ... to contain the comma so that the filter parsing code knows how...
Read more >
Method: translate
Translates input text, returning translated text. HTTP request. POST https://translation.googleapis.com/language/translate/v2.
Read more >
ngx-translate/core: The internationalization (i18n) library for ...
This method allows you to configure the TranslateModule by specifying a loader, a parser and/or a missing translations handler. import {BrowserModule} from '@ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found