npgsql / EntityFramework6.Npgsql

Entity Framework 6 provider for PostgreSQL
PostgreSQL License
66 stars 53 forks source link

42804: UNION types text and xml cannot be matched #173

Closed Thanseem007 closed 3 years ago

Thanseem007 commented 3 years ago

Hi guys,

I've created a model pointing to an existing PostgreSQL database. When I'm trying to query the database with below code.

               user = db.Employees.Where((User item) => item.email == email).
                        Include("Role").
                        Include("Group").FirstOrDefault();

In the Employee table there is a variable with data type as Xml. When I see the generated script. its try to union Xml variable with a text type. I think the text type is the default data type to which the nuget package convert if the corresponding varaible is ot in the other table.

Steps to reproduce

You can reproduce this error by doing a select query with two include methods and you have to set one parameter as Xml in database.

The issue

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message: 42804: UNION types text and xml cannot be matched
Stack trace: at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Npgsql.NpgsqlDataReader.<NextResult>d__46.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.<ExecuteDbDataReader>d__100.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)

Further technical details

Npgsql version: 4.0.10 PostgreSQL version: 12.4 Operating system: windows

Thanseem007 commented 3 years ago

image Adding to it

roji commented 3 years ago

This seems to be an EF6 issue - but the EF6 provider is pretty much archived at this point. I can accept specific, well-tested PRs to fix specific bugs, but am otherwise no longer actively working on it.

Emill commented 3 years ago

Entity Framework 6 is very limited to only the datatypes defined in EF6. XML is not one of them. Better use EF Core or something if you want support for more types. Everything else needs workarounds from your side.