Questions about converting to int in Sqlite
See original GitHub issueFor SQL Server, a number of Convert.ToX(value) functions are translated to CONVERT(X, @value)
which is great. I’m particularly interested in Convert.ToInt32.
Like many I use Sqlite for unit testing and found that it’s not translated for Sqlite. I do see a slew of new function mappings for 6.0 which is cool.
My question are:
- Is Convert.ToInt32 (and similar) on the cards for Sqlite?
- The translation for Convert.ToInt32 in SQL Server uses CONVERT, which is semantically the closest, but my understanding is that CAST functions very similarly- and because CAST is an ANSI-SQL standard, could a general relational translation be provided instead of a SQL Server specific one? I’m genuinely interested to learn about the subtle differences and the decision making process behind function mapping choices.
- I don’t think I can add CAST using
DbContext.HasDbFunction
(for either SQL Server or Sqlite) due to its unusual syntax, i.e. not just taking a parameter but alsoas int/integer
- is this correct or are there any workarounds?
EF Core version: Tried 3.1.13 / 5.0.4 / 6.0 preview 2 Database provider: Microsoft.EntityFrameworkCore.Sqlite
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Converting text to int in sqlite when querying
I want to convert both of the following columns to integer (they were placed as text in the SQlite db) as soon as...
Read more >Frequently Asked Questions
Short answer: A column declared INTEGER PRIMARY KEY will autoincrement. Longer answer: If you declare a column of a table to be INTEGER...
Read more >Sqlite spec: 4.2. Type Conversions Prior To Comparison
I would expect the following query: CREATE TABLE t (id integer primary key, str varchar(20)); INSERT ...
Read more >converting int to real in sqlite
If we divide an integer by another integer then the result value will be round off to the nearest integer. So, you can...
Read more >Untitled
If the tool doesn't convert your SQL file correctly please create an issue. ... Questions about converting to int in Sqlite #24526 -...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
SQLite provides an extension for a UINT collation that ignores leading zeros. You could also re-implement it in C#:
Thank you @bricelam, that’s a good tip. I probably wasn’t clear enough that I’m writing primarily against SQL Server, and was hoping to find something that worked against SQLite in unit tests too. That’s why I sought a function mapping for CAST which works for both. However always good to pick up new tips!