使用实体框架将文件保存在SQL Server 2008数据库中 [英] Save a file in SQL Server 2008 database with Entity Framework

查看:124
本文介绍了使用实体框架将文件保存在SQL Server 2008数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Entity Framework在SQL Server 2008数据库中保存文件?

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

我想在SQL Server 2008中使用FileStream。

I want to use FileStream in SQL Server 2008.

推荐答案

我不明白为什么这不行 - filestream code> varbinary(MAX)所以您应该可以使用实体框架设置列:

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:

here

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

这篇关于使用实体框架将文件保存在SQL Server 2008数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆