Взаимодействие с NpgsqlParameter
Редактировал(а) Alexandr Fokin 2024/12/07 13:48
public static class QueryParameterExtensions { public static NpgsqlParameter StructToDbParameter<T>( this T value, string name, NpgsqlDbType type ) where T : struct { return new NpgsqlParameter<T>(name, type) { TypedValue = value }; } public static NpgsqlParameter StructToDbParameter<T>( this T? value, string name, NpgsqlDbType type ) where T : struct { if (!value.HasValue) { return new NpgsqlParameter(name, type) { Value = DBNull.Value }; } return new NpgsqlParameter<T>(name, type) { TypedValue = value.Value }; } public static NpgsqlParameter ClassToDbParameter<T>( this T value, string name, NpgsqlDbType type ) where T : class { if (value == null) { return new NpgsqlParameter(name, type) { Value = DBNull.Value }; } return new NpgsqlParameter<T>(name, type) { TypedValue = value }; } } | |