问题
After much of googling I have come to three conclusion that until MVC 4 ( entity framework), that FILESTREAM (of Sql server) is not supported directly.
Is there a work around for the same?
回答1:
Unfortunatelly, there is no equivalent of FILESTREAM in EF 6, that could be used with Code First approach. There is a workaround I found today, but haven't tried myself yet, though:
http://ignoringthevoices.blogspot.co.uk/2014/01/working-with-entity-framework-code.html
Basicaly, you need to use database first and create column of VARBINARY(max) type. Then tell EF to ignore it when auto-mapping and use custom sql query to read/write the content.
Hope it helped.
回答2:
The best way for using FileStream Near Entity Framework Code first is things like this: in your model has one field with byte[] type and in up method of migration write this code :
DropColumn("dbo.Judges", "Photo");
Sql("alter table [dbo].[Judges] add [PhotoTemp] varbinary(max) FILESTREAM not null");
RenameColumn("dbo.Judges", "PhotoTemp", "Photo");
Sql("alter table [dbo].[Judges] add constraint [DF_Judges_Photo] default(0x) for [Photo]");
来源:https://stackoverflow.com/questions/19900028/is-there-a-workaround-to-enable-filestream-in-the-code-first-approach-of-entity