-
Notifications
You must be signed in to change notification settings - Fork 20
NULL values
sdrapkin edited this page Apr 27, 2017
·
4 revisions
NULL
T-SQL values are automatically converted into null
.NET reference values and Nullable<T>
struct values.
NULL
parameter values can be specified by explicitly typing anonymous-object properties as type-null or Nullable<T>
:
var result = await db.QueryAsync("UPDATE [SomeTable] SET [IntValue] = @Val WHERE [Id] = @Id",
new
{
@Id = new Guid("cf9fad7a-9775-28b9-7693-11e6ea3b1484"),
@Val = default(int?) // setting [IntValue] to NULL -- alternatively, "(int?)null"
});
If parameter values are specified via Dictionary<string, (object, Type)>
name-value mapping, use the .WithType()
helper extension on the null Nullable<T>
value to indicate NULL
:
var result = await db.QueryAsync("UPDATE [SomeTable] SET [IntValue] = @Val WHERE [Id] = @Id",
new Dictionary<string, object>
{
{ "@Id" , new Guid("cf9fad7a-9775-28b9-7693-11e6ea3b1484") },
{ "@Val" , default(int?).WithType() } // setting [IntValue] to NULL
});
Copyright (c) 2016-2022 Stan Drapkin