Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > BinaryImage > Loading image from Entity Framework

Not answered Loading image from Entity Framework

Feed from this thread
  • David avatar

    Posted on Nov 19, 2011 (permalink)

    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;
    }

    Reply

  • Kevin Master avatar

    Posted on Nov 22, 2011 (permalink)

    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.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > BinaryImage > Loading image from Entity Framework