【发布时间】:2013-12-02 01:26:36
【问题描述】:
我正在开发一个应用程序一段时间,我们需要添加迁移以在 SQL 服务器上启用 FILESTREAM。我的 Up() 方法如下所示:
public override void Up()
{
//Enable filestream
Sql("USE master " +
"Go " +
"EXEC sp_configure 'show advanced options' " +
"GO " +
"EXEC sp_configure filestream_access_level, 1 " +
"GO " +
"RECONFIGURE WITH OVERRIDE " +
"GO");
//Need to add some script here to create FILEGROUP and add a file to that
//file group to be used by FILESTREAM
CreateTable(
"dbo.PatientAttachmentEntities",
c => new
{
Id = c.Guid(nullable: false),
PatientMedicalDataId = c.Guid(nullable: false),
FileName = c.String(nullable: false),
FileDescription = c.String(),
})
.PrimaryKey(t => t.Id)
.ForeignKey("dbo.PatientMedicalDataEntities", t => t.PatientMedicalDataId, cascadeDelete: true)
.ForeignKey("dbo.AttachmentContentEntities", t => t.Id)
.Index(t => t.PatientMedicalDataId)
.Index(t => t.Id);
//CreateTable(
// "dbo.AttachmentContentEntities",
// c => new
// {
// Id = c.Guid(nullable: false),
// //Need to know if the following line is ok to setup a FILESTREAM column
// Content = c.Binary(storeType:"varbinary(max) FILESTREAM", nullable:true),
// })
// .PrimaryKey(t => t.Id);
Sql("CREATE TABLE [dbo].[AttachmentContentEntities]( " +
"[Id] [uniqueidentifier] ROWGUIDCOL NOT NULL PRIMARY KEY, " +
"[Content] [varbinary](max) FILESTREAM NOT NULL ) " +
"ON [PRIMARY] FILESTREAM_ON [MEDIC_FS]");
}
我需要一些 sql 脚本来添加一个文件组和一个文件到该组(该文件必须与我的数据库文件在同一路径上),我还需要知道我已经添加的脚本是否正常以及类型是否正确我把c.Binary方法装上都OK了。
非常感谢。
【问题讨论】:
标签: sql entity-framework filestream database-migration