Giter VIP home page Giter VIP logo

Comments (4)

erichiller avatar erichiller commented on July 17, 2024 1

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

roji avatar roji commented on July 17, 2024

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.

erichiller avatar erichiller commented on July 17, 2024

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.

roji avatar roji commented on July 17, 2024

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.