Skip to content

Commit

Permalink
Merge pull request #97 from alustrement-bob/fix-string-null-value
Browse files Browse the repository at this point in the history
Fix set null value on string property
  • Loading branch information
acupofjose authored May 23, 2024
2 parents ccfa515 + bf49aeb commit b27827d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Postgrest/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,13 @@ public IPostgrestTable<TModel> Set(Expression<Func<TModel, object>> keySelector,
throw new ArgumentException(
"Expression should return a KeyValuePair with a key of a Model Property and a value.");

if (value == null)
if (value == null && visitor.ExpectedType != typeof(string))
{
if (Nullable.GetUnderlyingType(visitor.ExpectedType) == null)
throw new ArgumentException(
$"Expected Value to be of Type: {visitor.ExpectedType.Name}, instead received: {null}.");
}
else if (!visitor.ExpectedType.IsInstanceOfType(value))
else if (value != null && !visitor.ExpectedType.IsInstanceOfType(value))
{
throw new ArgumentException(string.Format("Expected Value to be of Type: {0}, instead received: {1}.",
visitor.ExpectedType.Name, value.GetType().Name));
Expand Down
4 changes: 4 additions & 0 deletions PostgrestTests/LinqTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ await client.Table<KitchenSink>()
await client.Table<KitchenSink>()
.Set(x => x.BooleanValue, true)
.Update();

await client.Table<KitchenSink>()
.Set(x => x.StringValue!, null)
.Update();
}

[TestMethod("Linq: OnConflict")]
Expand Down

0 comments on commit b27827d

Please sign in to comment.