如何将二进制对象(即图形图片)保存为EF中的数据库字段? [英] How do I save a binary object (i.e., a graphics picture) as a database field in EF?

查看:268
本文介绍了如何将二进制对象(即图形图片)保存为EF中的数据库字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么:

VB 2010,EF 4.0,.NET 4.0,SQL Express

VB 2010, EF 4.0, .NET 4.0, SQL Express

我的问题:

如果我想让我的一个实体中的某个字段成为二进制对象 - 即图片或声音文件 - 我该如何设置它? (在EF设计器和运行时。)和
应该我在数据库文件中保存图片和声音等信息,或者我应该单独保存它们并且有文件名链接到他们在数据库中呢?

If I want one of the fields in one of my entities to be a binary object--i.e., a picture or sound file--how do I set that up? (In the EF designer and at run time.) And should I save such info as pictures and sound in the database files, or should I saved them seperately and have file-name links to them in the database instead?

Robert Gustafson

Robert Gustafson

推荐答案

根据您的工作流程,只需添加相应类型的列或属性:

Depending on your workflow just add a column or property of the appropriate type:

-in Database-First添加varbinary(max)列到你的数据库

-in Database-First add a varbinary(max) column to your database

-in Model-First添加一个二进制类型的列,其中Max Length = Max

-in Model-First add a column of type binary with Max Length = Max

-in Code-First添加一个类型的属性byte []

-in Code-First add a property of type byte[]

是的,把它们放在数据库中就可以了。如果你有大量的大文件SQL Server有一些额外的存储策略你可能会调查,比如使用blob的第二个文件组,或使用FileStream for SQL将文件存储在
NTFS中。 

And yes putting them in the database is fine. If you have a large number of large files SQL Server has some additional storage strategies you might investigate, like using a second filegroup for the blobs, or using FileStream for SQL to store the files in NTFS. 

David


这篇关于如何将二进制对象(即图形图片)保存为EF中的数据库字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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