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>Next, we will map the Items_Insert stored procedure so that it becomes the InsertFunction for the Items table. In the Mapping Details window click on the Map Entity toFunctions button, found on the right-hand side <strong>of</strong> the window (Figure 4-12).Figure 4-12:<strong>The</strong> Map Entity to Functions button.Click on the row and select Items_Insert from the drop-downlist. <strong>The</strong> parameters for the function are mapped correctly by default. In the ResultColumn Bindings node, type NewItemID (the name <strong>of</strong> the field in the return set <strong>of</strong> ourItems_Insert stored procedure) and press Enter. <strong>The</strong> designer will automatically andcorrectly map this value to the ItemID scalar property.Finally, we will map the GetSqlFileStreamInfo stored procedure to a function in thedata access layer. To add a function, right-click empty space in the Entity Model designerand click Add > Function Import. <strong>The</strong> Add Function Import dialog box (Figure 4-13)opens. Select the GetSqlFileStreamInfo stored procedure from the Stored ProcedureName drop-down list. Create a suitable name for the function, which in our example wewill keep the same as the stored procedure name.Our stored procedure returns a single row containing three columns. <strong>The</strong> structure <strong>of</strong>that row does not map to our Item entity though, so we will let the Entity Frameworkdesigner create a new class whose scalar properties map to the fields returned by thestored procedure.150

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

Saved successfully!

Ooh no, something went wrong!