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

Add support for binary blobs #38

Closed
abe545 opened this issue May 25, 2015 · 5 comments
Closed

Add support for binary blobs #38

abe545 opened this issue May 25, 2015 · 5 comments
Assignees
Milestone

Comments

@abe545
Copy link
Owner

abe545 commented May 25, 2015

Right now, they could be retrieved through an untyped data transformer (attribute, or IDataTransformer). However, it would be nice if the byte[] property could be specified without one.

@leevva
Copy link

leevva commented Dec 16, 2016

What do you mean by "untyped data transformer"?
Could you explain what i need to do to map varbinary(max) to byte[] ?

@abe545
Copy link
Owner Author

abe545 commented Dec 16, 2016

There is support for data transformation classes in the library. You can implement them with either the IDataTransformer class, or subclassing DataTransformerAttributeBase, and applying it to your property. I haven't tested this on a byte[], but conceptually it should work. The one reason why it may not work is that the library seems to be detecting this should be a hierarchical result set, and there is no matching result set.

Via DataTransformerAttributeBase:

class RawDataTransformerAttribute : DataTransformerAttributeBase
{
    public override object Transform(object value, Type targetType, bool isNullable) => value;
}

 internal class ContentSearchResultSet
 {
    [Column("raw"), RawDataTransformer]
    public byte[] Raw { get; set; }
    ...
}

Via IDataTransformer:

class ByteDataTransformer : IDataTransformer
{
    public bool CanTransform(object value, Type targetType, bool isNullable, IEnumerable<Attribute> propertyAttributes)
    {
        return targetType == typeof(byte[]);
    }

    public object Transform(object value, Type targetType, bool isNullable, IEnumerable<Attribute> propertyAttributes)
    {
        return value;
    }
}
...
StoredProcedure.Create("Foo")
               .WithDataTransformer(new ByteDataTransformer())

@leevva
Copy link

leevva commented Dec 19, 2016

Both variants don't work.
Probably the problem is in IsSimpleType method. I think for byte[] result of it should be true.
Then SimpleTypeRowFactory will be called:

            if (itemType.IsSimpleType())
                return new SimpleTypeRowFactory<T>();

instead of HierarchicalTypeRowFactory.

@abe545
Copy link
Owner Author

abe545 commented Dec 19, 2016

Yep, that would probably do it, to at least allow you to use the transformer. I'm hoping to be able to get to some of these issues over the next couple of weeks, but it is tough with the holidays...

@leevva
Copy link

leevva commented Dec 20, 2016

I hope this will happen as soon as possible. Look forward to that day.

@abe545 abe545 closed this as completed in #95 Jan 1, 2017
abe545 added a commit that referenced this issue Jan 1, 2017
@abe545 abe545 self-assigned this Jan 18, 2017
@abe545 abe545 added this to the 2.4.0 milestone Jan 18, 2017
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