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

How to have binary data in your POCO? #24

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

How to have binary data in your POCO? #24

gustavjon opened this issue Feb 3, 2017 · 5 comments
Assignees
Milestone

Comments

@gustavjon
Copy link

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
Copy link
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?

@VitaliyMF
Copy link
Contributor

VitaliyMF commented Feb 15, 2017

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

@gustavjon
Copy link
Author

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
Copy link
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.

@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
…pe when DbParameter should be used (command reused for several inserts/updates) #24
@VitaliyMF
Copy link
Contributor

Shipped in 1.0.1

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

No branches or pull requests

2 participants