Skip to content

Commit b27827d

Browse files
authored
Merge pull request #97 from alustrement-bob/fix-string-null-value
Fix set null value on string property
2 parents ccfa515 + bf49aeb commit b27827d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Postgrest/Table.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,13 @@ public IPostgrestTable<TModel> Set(Expression<Func<TModel, object>> keySelector,
474474
throw new ArgumentException(
475475
"Expression should return a KeyValuePair with a key of a Model Property and a value.");
476476

477-
if (value == null)
477+
if (value == null && visitor.ExpectedType != typeof(string))
478478
{
479479
if (Nullable.GetUnderlyingType(visitor.ExpectedType) == null)
480480
throw new ArgumentException(
481481
$"Expected Value to be of Type: {visitor.ExpectedType.Name}, instead received: {null}.");
482482
}
483-
else if (!visitor.ExpectedType.IsInstanceOfType(value))
483+
else if (value != null && !visitor.ExpectedType.IsInstanceOfType(value))
484484
{
485485
throw new ArgumentException(string.Format("Expected Value to be of Type: {0}, instead received: {1}.",
486486
visitor.ExpectedType.Name, value.GetType().Name));

PostgrestTests/LinqTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ await client.Table<KitchenSink>()
129129
await client.Table<KitchenSink>()
130130
.Set(x => x.BooleanValue, true)
131131
.Update();
132+
133+
await client.Table<KitchenSink>()
134+
.Set(x => x.StringValue!, null)
135+
.Update();
132136
}
133137

134138
[TestMethod("Linq: OnConflict")]

0 commit comments

Comments
 (0)