Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using wrong type for blob [DNET876] #806

Closed
firebird-issue-importer opened this issue Apr 11, 2019 · 8 comments
Closed

Using wrong type for blob [DNET876] #806

firebird-issue-importer opened this issue Apr 11, 2019 · 8 comments

Comments

@firebird-issue-importer

Submitted by: Vladimir Karataev (vladimir karataev)

Attachments:
ConsoleApp1.7z

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?

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 11, 2019

Commented by: @cincuranet

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?

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 11, 2019

Modified by: @cincuranet

status: Open [ 1 ] => In Progress [ 3 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 11, 2019

Commented by: Vladimir Karataev (vladimir karataev)

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[].

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 11, 2019

Commented by: @cincuranet

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.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 12, 2019

Commented by: Vladimir Karataev (vladimir karataev)

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.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 12, 2019

Modified by: Vladimir Karataev (vladimir karataev)

Attachment: ConsoleApp1.7z [ 13338 ]

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 15, 2019

Commented by: @cincuranet

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.

@firebird-issue-importer
Copy link
Author

@firebird-issue-importer firebird-issue-importer commented Apr 15, 2019

Modified by: @cincuranet

status: In Progress [ 3 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants