保存数据库的实体框架文件 [英] Save files in database with entity framework

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

问题描述

我必须建立在实体框架与Microsoft SQL Server 2008。我需要创建一个功能,可以让我的用户上传文件的ASP.NET MVC的解决方案。

I have an ASP.NET MVC solution built on Entity Framework with Microsoft SQL Server 2008. I need to create a function that lets my users upload files.

我想的是:


  • 使用实体框架在数据库中存储
  • 文件的解决方案
  • ,它通过某种散列/校验和
  • 从上传同一文件检测和prevents两次解
    在数据库/表设计
  • 温馨提示

  • A solution that uses the Entity Framework to store files in the Database
  • A solution that detects and prevents from uploading the same file twice via some kind of hash/checksum
  • Tips on database/table design

推荐答案

正确的方式来存储文件在SQL Server 2008数据库是<一个href=\"http://blogs.msdn.com/manisblog/archive/2007/10/21/filestream-data-type-sql-server-2008.aspx\">use在FILESTREAM数据类型。我不知道,实体框架支持,但你当然可以尝试,看看会发生什么。

The "right" way to store a file in a SQL Server 2008 database is to use the FILESTREAM data type. I'm not aware that the Entity Framework supports that, but you can certainly try and see what happens.

也就是说,大部分的时候,人们为此,他们不存储在数据库中的文件。这样做意味着你需要去通过ASP.NET和数据库服务器只服务,你可以直接从Web服务器提供服务的文件。它也可以稍微复杂的数据库和网站备份图片。因此,当我们将文件上传到我们的MVC /实体框架中,我们只存储在数据库中的文件位置的引用,并存储在文件本身别处

That said, most of the time when people do this, they don't store the file in the database. Doing so means that you need to go through ASP.NET and the database server just to serve a file which you could be serving directly from the web server. It can also somewhat complicate the backup picture for your database and site. So when we upload files to our MVC/Entity Framework, we store only a reference to the file location in the database, and store the file itself elsewhere.

显然,它的策略是适合你在很大程度上取决于应用程序的详情。

Obviously, which strategy is right for you depends a lot on the particulars of your application.

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

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