This is a migrated thread and some comments may be shown as answers.

Loading image from Entity Framework

1 Answer 123 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 19 Nov 2011, 10:24 AM
I have an image within the itemtemplate of a RadListView. I'm populating several of the controls within the template on the ItemDataBound event for the ListView with the Entity Framework. I'm new to the Entity Framework so need some help in figuring out how to populate the RadBinaryImage control.

The method I have for retrieving the image is this:

public static byte[] GetAccommodationMainImage(int accomID)
{
    byte[] image = null;
 
    using (var myEntity = new MyEntity1())
    {
        var photoRecord = (from accom in myEntity.WTO_Photos
                           where accom.accom_id == accomID
                           && accom.in_use_as_main == true
                           select accom).First();
        image = photoRecord.image;
    }
 
    return image;
}

1 Answer, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 22 Nov 2011, 02:32 PM
Hello David,

I'm assuming the Entity framework uses the same data type as Linq-to-SQL does when linking a VarBinary column, which I'm assuming is what your image column is. If so, the data type it uses is Binary. So to get the bytes from this field you can call photoRecord.image.ToArray().

I hope that helps.
Tags
BinaryImage
Asked by
David
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Share this question
or