Skip to content

Instantly share code, notes, and snippets.

@philippwiddra
Created October 6, 2017 11:57
Show Gist options
  • Save philippwiddra/cbcd26c160498183f8492ae7d3217ee6 to your computer and use it in GitHub Desktop.
Save philippwiddra/cbcd26c160498183f8492ae7d3217ee6 to your computer and use it in GitHub Desktop.
Example of how to use SQL Server FileTables with Entity Framework 6 Code First Migrations.
namespace Project.Migrations
{
using System;
using System.Data.Entity.Migrations;
public partial class FileTableAdded : DbMigration
{
public override void Up()
{
Sql(@"
CREATE TABLE [dbo].[ProfileImages]
AS FILETABLE
WITH (FILETABLE_DIRECTORY = N'ProfileImages', FILETABLE_COLLATE_FILENAME = Latin1_General_CI_AS)
");
}
public override void Down()
{
DropTable("dbo.ProfileImages");
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Project.Models
{
[Table("ProfileImages")]
public class ProfileImage
{
[Key]
[Column("stream_id")]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public Guid StreamId { get; set; }
[Column("file_stream")]
public byte[] FileStream { get; set; }
[Column("name")]
[StringLength(255)]
public string Name { get; set; }
//[Column("path_locator")]
//[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
//public byte[] PathLocator { get; set; }
//[Column("parent_path_locator")]
//[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
//public byte[] ParentPathLocator { get; set; }
[Column("file_type")]
[StringLength(255)]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string FileType { get; set; }
[Column("cached_file_size")]
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public long? CachedFileSize { get; set; }
[Column("creation_time")]
public DateTimeOffset CreationTime { get; set; }
[Column("last_write_time")]
public DateTimeOffset LastWriteTime { get; set; }
[Column("last_access_time")]
public DateTimeOffset? LastAccessTime { get; set; }
[Column("is_directory")]
public bool IsDirectory { get; set; }
[Column("is_offline")]
public bool IsOffline { get; set; }
[Column("is_hidden")]
public bool IsHidden { get; set; }
[Column("is_readonly")]
public bool IsReadOnly { get; set; }
[Column("is_archive")]
public bool IsArchive { get; set; }
[Column("is_system")]
public bool IsSystem { get; set; }
[Column("is_temporary")]
public bool IsTemporary { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment