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>Lab 3: <strong>FILESTREAM</strong> and LINQ to <strong>SQL</strong>This lab presents a very basic example that will help you to get started writing applicationsthat use LINQ to <strong>SQL</strong> classes to access the <strong>FILESTREAM</strong> data. Just as we saw withthe default EF approach in Lab 2a, LINQ to <strong>SQL</strong> also accesses <strong>FILESTREAM</strong> data throughT-<strong>SQL</strong> interfaces only; it is not capable <strong>of</strong> accessing the <strong>FILESTREAM</strong> data using Win32or Managed APIs.To complete this lab, we will follow the procedure below.1. Create a console application project.2. Add a LINQ to <strong>SQL</strong> class object to the project.3. Create a LINQ to <strong>SQL</strong> wrapper class for the Items table.4. Use LINQ to <strong>SQL</strong> to add a new row with a <strong>FILESTREAM</strong> value to the table.5. Query the table using LINQ to <strong>SQL</strong> and retrieve <strong>FILESTREAM</strong> data.Creating a new console application projectLet's get started. Open Visual Studio, and create a new console application project byselecting File | New | Project as demonstrated in the previous labs.Adding a LINQ to <strong>SQL</strong> class<strong>The</strong> next step is to add a LINQ to <strong>SQL</strong> class to the project. Right-click on the project inthe Solution Explorer and select Add | New Item. <strong>The</strong>n, in the Add New Item dialog box,select LINQ to <strong>SQL</strong> Classes, and rename the class to NorthPoleDB (Figure 4-14).158

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

Saved successfully!

Ooh no, something went wrong!