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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: <strong>FILESTREAM</strong> with Entity Framework and LINQ to <strong>SQL</strong>Create the stored procedure interfaceOur first step is to create a stored procedure for adding new items into the table (Listing4-3). This stored procedure will be invoked from the EF project.CREATE PROCEDURE [dbo].[SaveItem] (@ItemNumber VARCHAR(20),@ItemDescription VARCHAR(50),@ItemImage VARBINARY(MAX)) ASINSERT INTO dbo.Items(ItemGuid,ItemNumber,ItemDescription,ItemImage)SELECTNEWID(),@ItemNumber,@ItemDescription,@ItemImageRETURN SCOPE_IDENTITY()Listing 4-3:Creating a stored procedure to add items to the table.Note that this procedure accepts item information including the image, which will goto the <strong>FILESTREAM</strong> column <strong>of</strong> the table. Because we are using the T-<strong>SQL</strong> interface forwriting into the <strong>FILESTREAM</strong> column, a VARBINARY(MAX) variable is used. Rememberthat the <strong>FILESTREAM</strong> columns appear as VARBINARY(MAX) data type values whenaccessing them from T-<strong>SQL</strong>.135

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

Saved successfully!

Ooh no, something went wrong!