开发者

Save a file in SQL Server 2008 database with Entity Framework

How can I save a file in SQL Server 2008 database with Entity Framework?

I want to use FileStream in SQL开发者_如何学Go Server 2008.


I don't see why this wouldn't work - filestream columns are just exposed as varbinary(MAX) so you should be able to set the column using Entity Framework:

Sample from here:

Files newFile = new Files();
newFile.FileID = Guid.NewGuid();
newFile.FileContents = System.IO.File.ReadAllBytes("TextFile1.txt");
ctx.AddObject("Files", newFile);
ctx.SaveChanges();


Entity framework doesn't have support for SQL server specific features like filestream. You can't do it with EF you must fall back to ADO.NET.

Edit:

Undeleting my answer because I just tested how EF handles FILESTREAM columns. EF indeed works with FILESTREAM column so my answer is not fully correct and @BrokenGlass provided the solution. The problem is that EF ignores FILESTREAM keyword and doesn't really use streaming when working with FILESTREAM column. That column is handled as any other binary column.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜