Issue Details (XML | Word | Printable)

Key: DNET-876
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Jiri Cincura
Reporter: Vladimir Karataev
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
.NET Data provider

Using wrong type for blob

Created: 11/Apr/19 12:03 PM   Updated: 15/Apr/19 06:22 AM
Component/s: ADO.NET Provider
Affects Version/s: 6.6.0.0
Fix Version/s: None

File Attachments: 1. File ConsoleApp1.7z (202 kB)

Environment:
Asp.net core, microsoft.entityframeworkCore 2.2.4
Firebird 2.5


 Description  « Hide
I am using next data model:

[Table("table")]
public class Test
{
[Key][Required]
public long Id {get; set; }

[Column("raw_data")]
public byte[] raw_data {get; set; }
}

The column "raw_data" was descripted as: BLOB SUB_TYPE 1 SEGMENT SIZE 100 CHARACTER SET UTF8;

This is a BLOB.

I execute request of data from table through entity framework:

var data = db.Test.Find(id);

In window trace into visual studio i watch query:

SELECT "e"."ID", "e"."RAW_DATA" FROM "TABLE" AS "e" WHERE "e"."ID" = CAST(@__get_Item_0 AS BIGINT)

I have got exception in this place:

"Unable to cast object of type 'System.String' to type 'System.Byte[]'."

I suppose, provider should be using blob type for this column, but it using type of string for this column. May be it wrong behavior?

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Jiri Cincura added a comment - 11/Apr/19 12:20 PM
The table on latest providers gets this definition:
CREATE TABLE "table" (
    "Id" BIGINT NOT NULL,
    "raw_data" BLOB SUB_TYPE BINARY,
    CONSTRAINT "PK_table" PRIMARY KEY ("Id")
);

Which is correct.

Even the query is different:
      SELECT "e"."Id", "e"."raw_data"
      FROM "table" AS "e"
      WHERE "e"."Id" = CAST(@__get_Item_0 AS BIGINT)
      ROWS (1)

Can you provide reproducible test code?

Vladimir Karataev added a comment - 11/Apr/19 03:16 PM
Provider work fine with SUB_TYPE BINARY, and map on byte[] type in c# code.
Problem only with SUB_TYPE 1.

I found workaround: db.Test.FromSql("...cast(raw_Data as blob sub_type 0)...")

An sad moments in such case. Entity generate query like "select from select".

And interesting moment. On UPDATE query byte[] mapping on BLOB SUB_TYPE 1 perfect.

Only SELECT query make wrong mapping BLOB SUB_TYPE 1 to string, but not to byte[].

Jiri Cincura added a comment - 11/Apr/19 04:06 PM
SUB_TYPE 1 is text/string. Doesn't make sense with byte[].

The rest I don't understand. Unless I see some simple failing code, there's not much I can do.

Vladimir Karataev added a comment - 12/Apr/19 10:27 AM - edited
Why all operations with blob sub_type 1 as byte[] work fine, and only select is wrong? If SUB_TYPE 1 = text/string, than all operations should work with blob as string. An other hand, If SUB_TYPE 1 may be as byte[], than all oprations should work with blob as byte[]. Now I demonstrate mixed behavior with blob sub_type 1, when in some operations i can use byte[], and in select i can't use byte[].

Demo was be attached to ticket.

Jiri Cincura added a comment - 15/Apr/19 06:22 AM
Your mapping is wrong. You have the column as "BLOB SUB_TYPE 1", which is expected to be string. If you want to use "byte[]", use sub type 0.