Storing images in SQL Server with RIA Services - by Peter Kuhn (@Mister_Goodcat)
In the Silverlight forums people frequently ask for help with storing images in their databases using RIA Services. Even though this looks like a pretty common thing to do, it is far from being straight forward, and searching the web does not seem to produce any good results (or I'm just doing it wrong). So I decided to write this quick walk-through of how to do that. This post describes all steps and possible pitfalls to create a complete application for this from scratch, from the database to the UI.
Table of contents:
- Setting up the project
- Creating the model
- Setting up the image entity
- Setting up the image data entity
- Setting up the relation
- Creating the database
- Problems with the database generation/rework
- Creating the domain service
- Downloading MVVM Light with NuGet
- Creating a simple client UI
- Extending the client side model
- Conversion of the images
- The view model
- Loading the available images
- Loading the selected image's data
- Deleting images
- Adding new images
- Further considerations
- Potential problems
- Summary and source code download
I am not a DBA. Those DBAs I know frown upon things like storing images as blob data in the database. The preferred solution everybody seems to recommend is to only store the meta data in your database and link that to a file in the file system. But still, I did come across situations where I had to design a system like that, for example if a customer had a demand for it out of whatever reasons. Also, it's not true that blob storage in the database is worse than using the file system in any case. If you are interested in more details on the topic, I recommend the following report from Microsoft Research: To blob or not to blob? It claims that for objects of size 256 KBytes or lower storing the binary data in the database has clear advantages over the file system, for sizes of 1 MB or more the file system is a better choice. Inside that range, it depends on the scenario. That report is from 2006 and I very much believe that the situation has not worsened for the database storage since that time.
So, whether the way provided here is suitable for you or not solely depends on your project environment and own research, I don't make any recommendations on this. I also will not make any performance optimizations or similar in this post, it is just meant as a demonstration of how the basic mechanism works, with focus on the client side and middleware.
Read More from: Original Source
Post Contributed by: Kunal Chowdhury
Kunal is the Site Admin and Contributor of Silverlight-Zone. He is a Software Engineer, Microsoft Silverlight MVP, Code Project Mentor and a Code Project MVP. He is also an active Author in SilverlightShow.net and a speaker in various community events. He works on Microsoft Platform and very passionate about Silverlight technology. He started his career in 2007 and achieved various awards during his professional life.
He shares his findings in his personal blog: http://www.kunal-chowdhury.com and he also tweets at: @kunal2383.