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>Adding a new rowLet us see how to add a new row into the Items table using LINQ to <strong>SQL</strong> classes, andpopulate the <strong>FILESTREAM</strong> column. Listing 4-11 shows the C# code to do this.static void SaveItem(){Item itm = new Item();itm.ItemDescription = "Micros<strong>of</strong>t Mouse";itm.ItemGuid = System.Guid.NewGuid();System.Data.Linq.Binary img;img = new System.Data.Linq.Binary(System.IO.File.ReadAllBytes("c:\\temp\\Micros<strong>of</strong>tMouse.jpg"));itm.ItemImage = img;itm.ItemNumber = "IT001";}NorthPoleDBDataContext db = new NorthPoleDBDataContext();db.Items.InsertOnSubmit(itm);db.SubmitChanges();db.Dispose();Listing 4-11:Adding a new row using LINQ to <strong>SQL</strong>.Querying <strong>FILESTREAM</strong> data using LINQ to <strong>SQL</strong><strong>The</strong> final step in this lab is to see how to query and retrieve <strong>FILESTREAM</strong> data usingLINQ to <strong>SQL</strong> classes. Listing 4-12 searches for an item with a specific item number andretrieves the <strong>FILESTREAM</strong> value associated with the row.162

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

Saved successfully!

Ooh no, something went wrong!