Search code examples
c#visual-studioentity-frameworkef-code-firstcode-first

How to store a picture using Entity Framework


How to store a picture using Entity Framework?


Solution

  • Several options come to my mind:

    1. Use a [varbinary] column in DB table and store the bytes of the image.
    2. Convert image data to Base64 and store in DB table as varchar(MAX). This way you can use the Base64 string in the html "img" tag directly
    3. Rather than storing static files in DB - why not store the images in a directory that your web server can serve. And store the Path to the image in the Database. In the html set the "img" tag src to the path