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

How to have binary data in your POCO? #24

Closed
gustavjon opened this Issue Feb 3, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@gustavjon

gustavjon commented Feb 3, 2017

I could use some help inserting binary data.

The database I'm using is sql server 2014. The column i'm trying to insert som bytes into looks like this:

[BinaryData]varbinary NULL,

In my code the property looks like this:

public byte?[] BinaryData { get; set; }

I'm simply inserting this using

dbAdapter.Insert("MyTable", entity);

but when It's inserted I get this exception "Implicit conversion from data type nvarchar to varbinary(max) is not allowed".

If I comment out the binary property everything works just fine.

I've tried adding the Column annotation like this on the property in my code but that didnt help.

[Column(“BinaryData", TypeName="varbinary")]

Some help would be much appreciated.

@VitaliyMF

This comment has been minimized.

Show comment
Hide comment
@VitaliyMF

VitaliyMF Feb 3, 2017

Contributor

@gustavjon I may assume that problem in the "byte?[]" type - it is not detected as known type for varbinary sql type. Could you try "byte[]" and let me know about the results?

Contributor

VitaliyMF commented Feb 3, 2017

@gustavjon I may assume that problem in the "byte?[]" type - it is not detected as known type for varbinary sql type. Could you try "byte[]" and let me know about the results?

@VitaliyMF VitaliyMF added the question label Feb 3, 2017

@VitaliyMF

This comment has been minimized.

Show comment
Hide comment
@VitaliyMF

VitaliyMF Feb 15, 2017

Contributor

@gustavjon is your question still actual? Could you provide any update?

Contributor

VitaliyMF commented Feb 15, 2017

@gustavjon is your question still actual? Could you provide any update?

@gustavjon

This comment has been minimized.

Show comment
Hide comment
@gustavjon

gustavjon Feb 15, 2017

I tried byte[] but I had the same problem. I decided to write a stored procedure instead but I actually ran into the same error doing that when I tried to insert null so in the end I had to make the column default to null rather then inserting a null value.

gustavjon commented Feb 15, 2017

I tried byte[] but I had the same problem. I decided to write a stored procedure instead but I actually ran into the same error doing that when I tried to insert null so in the end I had to make the column default to null rather then inserting a null value.

@VitaliyMF

This comment has been minimized.

Show comment
Hide comment
@VitaliyMF

VitaliyMF Feb 17, 2017

Contributor

@gustavjon I've performed some tests with SQL server and "varbinary" column type and found the following:

  • when model has "byte[]" property with null value, suggested parameter type is varchar and this causes convert issue (unit tests use SQLite and it works without any errors in this case). Resolution should be setting DbParameter type explicitly if parameter value is null
  • when model has "byte[]" property with binary data, it is incorrectly passed as parameter.

Thank you for reporting about the issue! I'll try to provide bugfix release soon.

Contributor

VitaliyMF commented Feb 17, 2017

@gustavjon I've performed some tests with SQL server and "varbinary" column type and found the following:

  • when model has "byte[]" property with null value, suggested parameter type is varchar and this causes convert issue (unit tests use SQLite and it works without any errors in this case). Resolution should be setting DbParameter type explicitly if parameter value is null
  • when model has "byte[]" property with binary data, it is incorrectly passed as parameter.

Thank you for reporting about the issue! I'll try to provide bugfix release soon.

@VitaliyMF VitaliyMF added the bug label Feb 17, 2017

@VitaliyMF VitaliyMF added this to the 1.0.1 milestone Feb 17, 2017

@VitaliyMF VitaliyMF self-assigned this Feb 17, 2017

VitaliyMF added a commit that referenced this issue Feb 17, 2017

VitaliyMF added a commit that referenced this issue Feb 17, 2017

Avoid using DbParameter for NULL values + workaround for varbinary ty…
…pe when DbParameter should be used (command reused for several inserts/updates) #24
@VitaliyMF

This comment has been minimized.

Show comment
Hide comment
@VitaliyMF

VitaliyMF Mar 3, 2017

Contributor

Shipped in 1.0.1

Contributor

VitaliyMF commented Mar 3, 2017

Shipped in 1.0.1

@VitaliyMF VitaliyMF closed this Mar 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment