Comments (4)
@erichiller at the moment, the last version is the only one that works: DBNull.Value is the way to represent a database null value.
This is an unfortunate situation which I hope to resolve, but it's important to think about all this in the context of the .NET data API (ADO.NET), and not just Npgsql. In the meantime, you can have an extension method which adds a non-generic parameter with DBNull.Value for a null value, and a generic one with the non-null value otherwise.
Thanks for the information. It might be good to have this in the official docs. I would be happy to add if you'd like.
from doc.
It seems you are conflating positional parameters (with no name) and the generic NpgsqlParameter<T>
: you can (and should) use positional parameters with the non-generic NpgsqlParameter just fine.
The problem of passing null when using the generic NpgsqlParameter<T>
with .NET value types is tracked by npgsql/npgsql#3679.
from doc.
Which non-generic variant should be used? I've tried:
new NpgsqlParameter { NpgsqlDbType = NpgsqlDbType.Double, NpgsqlValue = nullableDouble } ;
// System.InvalidCastException: Parameter must be set
new NpgsqlParameter { NpgsqlValue = nullableDouble } ;
// System.InvalidOperationException: Parameter '$5' must have either its NpgsqlDbType or its DataTypeName or its Value set
new NpgsqlParameter { Value = nullableDouble } ;
// System.InvalidOperationException: Parameter '$5' must have either its NpgsqlDbType or its DataTypeName or its Value set
new NpgsqlParameter( nullableDouble ) ;
// Cannot resolve constructor 'NpgsqlParameter(System.Nullable<double>)', candidates are...
/* The only one I've gotten to work */
nullableDouble is {} nonNullableDouble ? new NpgsqlParameter{ NpgsqlValue = nonNullableDouble, NpgsqlDbType = NpgsqlDbType.Double } : new NpgsqlParameter{ Value = DBNull.Value } ;
from doc.
@erichiller at the moment, the last version is the only one that works: DBNull.Value is the way to represent a database null value.
This is an unfortunate situation which I hope to resolve, but it's important to think about all this in the context of the .NET data API (ADO.NET), and not just Npgsql. In the meantime, you can have an extension method which adds a non-generic parameter with DBNull.Value for a null value, and a generic one with the non-null value otherwise.
from doc.
Related Issues (20)
- Document Npgsql.DependencyInjection
- Document that logging support is removed in v7 HOT 1
- Full text query parse issue HOT 1
- TCP Keep Alive time is in s, the documentation say ms HOT 3
- Enum docs should be updated given deprecation of GlobalTypeMapper
- Update documentation for using NetTopologySuite/NodaTime with NpgsqlDataSource HOT 2
- Improve FAQ page
- Small error on collations docs HOT 1
- Add NpgsqlCidr type to v8 Release Notes HOT 3
- Document unmapped composite support
- Document ExecuteScalar returning null for void where it returned DBNull
- Add Note about unsupported Regex options HOT 2
- Proposal: Migrate to mkdocs HOT 2
- Release notes for Net8 (Breaking changes, JSON POCO) doesn't link to correct documentation pages HOT 1
- Basic Usage NpgsqlCommand ExecuteReaderAsync Return Value Is Wrong HOT 2
- Should remove IntegratedSecurity from the doc HOT 1
- I have an optimization suggestion regarding the Npgsql website. HOT 1
- Undocumented breaking change of stringValue.Contains(value) in v8 HOT 1
- Nullable value types in 8.0 on Release Notes vs Strongly Typed Parameters on Basic Usage
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 doc.