BTI-Doug
BTI-Doug

Reputation: 463

Code first filetable in SQL Server

Trying to take advantage of the FileTables feature in SQL Server 2012 in my current MVC5 project. Does anyone have any examples of how to create the file table "table" using code first? All of my tables, indexes, etc. are done using code first and I'd like to continue that practice here.

Upvotes: 3

Views: 3489

Answers (3)

DarcyThomas
DarcyThomas

Reputation: 1288

You can add custom SQL in a Code First Migration.

  • Create a migration Add-Migration
  • Put In some Custom SQL to Enable Filestreams
  • Update the db with Update-Database

Example migration with custom SQL:

public partial class AddFileStreamMigration: DbMigration 
{ 
    public override void Up() 
    { 
        var customSql = @"ALTER DATABASE Photos
                          SET FILESTREAM (NON_TRANSACTED_ACCESS = FULL)
                          GO

                          etc...";
        Sql(customSql ); 
    } 

    public override void Down() 
    { 
        //Make sure you put in roll back SQL too!
    } 
}     

```

Upvotes: 1

Mentor
Mentor

Reputation: 3355

The decision is available here: "WEB API FILE UPLOAD WITH MS SQL SERVER FILETABLE" https://damienbod.wordpress.com/2014/04/08/web-api-file-upload-with-ms-sql-server-filetable/

Upvotes: 1

Atchitutchuk
Atchitutchuk

Reputation: 184

Unfortunately I cannot help you with FileTable, but this example of FileStream (similar thing in many ways) works quite well.

Upvotes: 1

Related Questions