Comments (4)
That is all covered in the docs: columns/table names cannot be parameterized in databases, so you must use string interpolation to construct your SQL, and that can vulnerable to SQL injection. What point exactly do you think isn't covered in the docs?
from efcore.pg.
I apologize for the incorrect test example with the table name. I will give an example from real code, where there is no reference to table names or any other part of the schema.
Used Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite 8.0.0
This code have EF1002 warning, but work correct. How can I rewrite the code correctly so that I don't get EF1002?
var point = new Point(10, 10);
var tolerance = 50;
var wktPoint = point.ToText().Replace(",", "");
var bufferedPoint = await dbContext.Database
.SqlQueryRaw<Geometry>($"SELECT ST_Buffer(ST_GeogFromText('{wktPoint}'), {tolerance}, 8) as \"Value\"")
.FirstOrDefaultAsync(cancellationToken: cancellationToken);
I try this, but have error.
var point = new Point(10, 10);
var tolerance = 50;
var wktPoint = point.ToText().Replace(",", "");
var bufferedPoint = await dbContext.Database
.SqlQueryRaw<Geometry>("SELECT ST_Buffer(ST_GeogFromText('@wktPoint'), @tolerance, 8) as \"Value\""
,new NpgsqlParameter<string>("wktPoint",wktPoint),new NpgsqlParameter<int>("tolerance",tolerance))
.FirstOrDefaultAsync();
from efcore.pg.
Why are you using SqlQueryRaw as opposed to SqlQuery, which provides parameter safety?
from efcore.pg.
I understood what the problem was. I called the method like this and got an error. I didn’t notice that this construction is not string interpolation. Single quotes '{wktPoint}' played a cruel joke on me. Thank you for helping me figure out the problem, sorry for wasting your time
.SqlQuery<Geometry>($"SELECT ST_Buffer(ST_GeogFromText('{wktPoint}'), {tolerance}, 8) as \"Value\"")
//valid variant
.SqlQuery<Geometry>($"SELECT ST_Buffer(ST_GeogFromText({wktPoint}), {tolerance}, 8) as \"Value\"")
from efcore.pg.
Related Issues (20)
- Question: SQL LEFT JOIN clause varies based on declarative- vs. method-style join HOT 1
- Fully support extensions create in non-default schemas
- Make the enumName parameter in NpgsqlDbContextOptionsBuilder.MapEnum<T>() optional. HOT 7
- How to prefix an update statement with a SET, whilst maintaining DbConcurrencyException logic HOT 3
- All migrations detected as Pending if you don't have a versioned public schema.
- EntityTypeBuilder.HasCluster(string indexName) HOT 1
- Remove-Migration throws System.NullReferenceException when using NpgsqlRange<DateTimeOffset>
- Drop custom collation in EF migration rollback
- Translate range construction, e.g. NpgsqlRange<DateTime> to daterange() HOT 2
- Updating a datetime property through ExecuteUpdateAsync() forces the datetime to be UTC? HOT 4
- Look into TimescaleDB support
- Method 'get_ConstructorExpression' in type 'JsonBigIntegerReaderWriter' from assembly 'Npgsql.EntityFrameworkCore.PostgreSQL' does not have an implementation. HOT 7
- Slow performance on string contains expression. HOT 23
- ENUMs don't use fully qualified namespaces in ModelSnapshot which causes collisions HOT 2
- Plans for Entity Framework 9 (EF9) support? HOT 2
- Question: Correct way to rotate database credentials when using a datasource HOT 5
- Additional DateOnly related translation
- Missing checks for predicate when simplifying primitive collections
- Translation error when storing NodaTime `(Instant, TimeZoneId)` and filtering on local date time values HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from efcore.pg.