17.07.2015 Views

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

The Art of SQL Server FILESTREAM - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4: <strong>FILESTREAM</strong> with Entity Framework and LINQ to <strong>SQL</strong>static void Main(string[] args){NorthPoleDBDataContext db = new NorthPoleDBDataContext();var itms = from p in db.Itemswhere p.ItemNumber == "IT001"select p;}foreach (var itm in itms){Console.WriteLine("Item Description = {0}",itm.ItemDescription);System.IO.File.WriteAllBytes("c:\\temp\\Micros<strong>of</strong>tMouse.jpg",itm.ItemImage.ToArray());}db.Dispose();Listing 4-12:Querying a <strong>FILESTREAM</strong> table using LINQ to <strong>SQL</strong>.Now run your application or debug and step through the code to see how it works.Remember, LINQ to <strong>SQL</strong> accesses <strong>FILESTREAM</strong> data through the T-<strong>SQL</strong> interface.Streaming access to the <strong>FILESTREAM</strong> data is not available when accessing it throughLINQ to <strong>SQL</strong>. This might result in performance problems on systems that perform a largenumber <strong>of</strong> <strong>FILESTREAM</strong> operations using LINQ to <strong>SQL</strong>.SummaryWe have seen how to write applications that access <strong>FILESTREAM</strong> data usingADO.NET EF and LINQ to <strong>SQL</strong>. <strong>The</strong> former is one <strong>of</strong> the most popular objectrelational mapping frameworks available for .NET. <strong>The</strong> latter <strong>of</strong>fers simplicityand remains a viable data access option, but has become less prevalent followingthe introduction <strong>of</strong> Entity Framework.163

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!