Skip to content

Commit 668ded1

Browse files
author
Eric Dagenais
committed
fixes "System.NotSupportedException: CLR type System.Object isn't supported by Npgsql" type exceptions when using IncludeOptimized with Npgsql and a query that employs a x => array.Contains(x.Id) type expression.
This commit fixes the following use case which would previously throw the above System.NotSupportedException when using Npgsql (a .NET Postgres client SDK): ``` var ids = new Guid [] { Guid.Parse("838de2e2-d18d-49d1-8f03-7351a6e99a55d"), Guid.Parse("9380a5dc-ceb6-4fa4-a30b-a583d1ba00b") }; var entities = await _dbContext.MainRows .Where(x => ids.Contains(x.Id)) .IncludeOptimized(x => x.ChildRows) .ToListAsync(); ```
1 parent 793deb7 commit 668ded1

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/shared/Z.EF.Plus._Core.Shared/EF/DbParameter/DbParameter.CopyFrom.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public static void CopyFrom(this DbParameter @this, DbParameter from)
5555
var property = from.GetType().GetProperty("OracleDbType");
5656
property.SetValue(@this, property.GetValue(from, null), new object[0]);
5757
}
58+
else if (fullName.Contains("Npgsql") && from.GetType().GetProperty("NpgsqlDbType") != null)
59+
{
60+
var property = from.GetType().GetProperty("NpgsqlDbType");
61+
property.SetValue(@this, property.GetValue(from, null), new object[0]);
62+
}
5863
#endif
5964

6065
@this.Value = from.Value ?? DBNull.Value;
@@ -90,6 +95,11 @@ public static void CopyFrom(this DbParameter @this, DbParameter from, string new
9095
var property = from.GetType().GetProperty("OracleDbType");
9196
property.SetValue(@this, property.GetValue(from, null), new object[0]);
9297
}
98+
else if (fullName.Contains("Npgsql") && from.GetType().GetProperty("NpgsqlDbType") != null)
99+
{
100+
var property = from.GetType().GetProperty("NpgsqlDbType");
101+
property.SetValue(@this, property.GetValue(from, null), new object[0]);
102+
}
93103
#endif
94104

95105
@this.Value = from.Value ?? DBNull.Value;

0 commit comments

Comments
 (0)