Loading image from Entity Framework

2 posts, 0 answers
  1. David
    David avatar
    10 posts
    Member since:
    Jul 2011

    Posted 19 Nov 2011 Link to this post

    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;
    }
  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 22 Nov 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top