-
Notifications
You must be signed in to change notification settings - Fork 20
NULL values
sdrapkin edited this page Feb 13, 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>
name-value mapping, use the type of the parameter as its value to indicate null
value:
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" , typeof(int?) } // setting [IntValue] to NULL
});
Copyright (c) 2016-2022 Stan Drapkin