- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
假设我的 SQL Server 2012 数据库中有以下表格:
Person
PersonId
FirstName
LastName
Photo
PhotoId
PersonId (fk)
DateTaken
PhotoFileTable
(all the FileTable columns)
存储在磁盘上的照片结构如下:\\myserver\filestreamshare\People\PersonId\Photo1.tif
而且非常重要:磁盘上已经有大量照片需要添加到数据库中 - 这就是为什么我认为 FileTable 会很酷,因为它会自动拾取它们。
所以我需要做两件事 - 首先,将 Photo 表与 PhotoFileTable 相关联,这样我就可以获取一个人的所有照片。其次(也是更痛苦的)我想使用 Entity Framework 5.0 来做到这一点。
使用 edmx 设计器,我无法添加包含 hierarchyid 的表。由于这是主键,它似乎应该用作 PhotoId 和 path_locator(FileTable hierarchyid)之间的 1:1 映射。但是我也无法添加照片表。
最好的方法是什么?归根结底,我想使用 C# 中的 EF 对象。理想情况下它看起来像:
class Person
List<Photo>
class Photo
Filestream (to lazy load the image from the filesystem to bitmapimage)
Path (?)
or maybe
class Photo
BitmapImage (lazy load)
我是不是用错了方法?我可以从这里到那里吗?想法或建议?
最佳答案
也许你可以试试这个。
表:
PhotoTable(
PhotoID uniqueidentifier ROWGUIDCOL NOT NULL,
PhotoImage varbinary(max) FILESTREAM NULL,
)
插入:
create procedure spPhotoInsert
@PhotoID uniqueidentifier
,@sPhotoPath nvarchar(max)
,@PhotoImage varbinary(max)
as
begin
select
cast('' as varbinary(max)) PhotoImage
into
#ret1
truncate table #ret1
declare @strSql nvarchar(max) = 'select * from OPENROWSET(BULK '''
+ @sPhotoPath + ''',SINGLE_BLOB) AS PhotoImage'
insert into #ret1 EXEC(@strSql)
insert into
PhotoTable
(
PhotoID
,PhotoImage
)
select
@PhotoID
,PhotoImage
from
#ret1
drop table #ret1
end
更新:
create procedure spPhotoUpdate
@PhotoID uniqueidentifier
,@sPhotoPath nvarchar(max)
,@PhotoImage varbinary(max)
as
begin
select
cast('' as varbinary(max)) PhotoImage
into
#ret1
truncate table #ret1
declare @strSql nvarchar(max) = 'select * from OPENROWSET(BULK '''
+ @sPhotoPath + ''',SINGLE_BLOB) AS PhotoImage'
insert into #ret1 EXEC(@strSql)
update
PhotoTable
set
PhotoImage = r.PhotoImage
from
PhotoTable, #ret1 r
where
PhotoID = @PhotoID
drop table #ret1
end
删除:
create procedure PhotoDelete
@PhotoID uniqueidentifier
as
begin
delete
PhotoTable
where
PhotoID = @PhotoID
end
和 View :
CREATE VIEW vPhotoTable
AS
select
PhotoID
,'' as sPhotoPath
,PhotoImage
from
PhotoTable
在此之后,可以使用 EF 读取/写入图像,如下所示:
//InsertPhoto(sPath)
Entities db = new Entities();
vPhoto p = db.vPhotos.CreateObject();
p.PhotoID = Guid.NewGuid();
p.sPhotoPath = sPath;
db.vPhotos.AddObject(p);
db.SaveChanges();
//UpdatePhoto(PhotoID,sPath):
Entities db = new Entities();
vPhoto p = db.vPhotos.Where(x => x.PhotoID == PhotoID).Single();
p.sPhotoPath = sPath;
db.ObjectStateManager.ChangeObjectState(p, EntityState.Modified);
db.SaveChanges();
//DeletePhoto(PhotoID):
Entities db = new Entities();
vPhoto p = db.vPhotos.Where(x => x.PhotoID == PhotoID).Single();
db.vPhotos.DeleteObject(p);
db.SaveChanges();
关于c# - Entity Framework 5.0 和 FileTable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13181645/
最近,我们的团队正在考虑使用 FILESTREAM 来扩展我们专有应用程序的功能。该应用程序的主要目的是管理我们制造的所有零件的各种 PDF、图像和文档。我们的 ASP 应用程序使用一些第三方工具来允
我刚刚开始在 SQL Server 2012 中使用 FileTables。我已经在远程服务器上设置了所有内容,并且没有任何问题。非事务性文件插入等工作得非常好。 但是,当我尝试从 Windows 资
FileTable是基于FILESTREAM的一个特性。有以下一些功能: •一行表示一个文件或者目录。 •每行包含以下信息: • •file_Stream流数据,stream_id标示符(GU
我准备在 SQL Server 2012 中使用 FileTable 功能,但我不清楚备份如何与此功能配合使用: 1) 完整数据库备份是否包括 FileTable 文件? 2) 例如,我将如何执行单个
有没有办法在 FileTable 中创建目录不使用文件 I/O API?是否和创建 SQL INSERT 语句一样简单? 这是我第一次使用 SQL Server 2012,我不熟悉 FileTable
我正在考虑使用文件表,而不是简单地将文件作为二进制数据存储在数据库中,或者在数据库中存储包含文件共享 URL 的列。我们的应用程序使用 Entity Framework ,所以这是我看到的一个小问题,
之前,I requested how to create a directory within a FileTable without using File I/O APIs 。我现在想为刚刚创建的父
我有一个表“game.FileAttachments”,它有一个stream_id 列,该列链接到文件表“game.Attachments”的stream_id 列。我在文件表上创建了一个更新触发器,
假设我的 SQL Server 2012 数据库中有以下表格: Person PersonId FirstName LastName Photo PhotoId PersonId
我尝试使用 File I/O API 将图像文件插入到 SQL Server FileTable 目录中。我需要获取 stream_id插入图像并将其用作另一个表作为外键。 任何人都可以帮助我,我如何
如果我在 SQL Server 2012 中创建一个 FileTable,然后将一个 4G 文件放到 NT 文件系统(在文件流中),整个 4G 文件是否会被读入表的文件流列? SQL 实际上是在复制我
我正在研究文档存储。因此我计划将 SqlServer 2012 与文件表一起使用。 现在经过一些测试,似乎 SqlServer 只索引 doc 而不是 docx 文件。 我还安装了 Microsoft
我正在尝试通过存储过程在 SQL Server FileTable 中创建目录,我在其中调用以下代码: INSERT INTO tblMyFiles (name, is_directory, is_a
我正在尝试使用 WCF 服务中的 SqlFileStream 对象来获取 SQL Server 2012 FileTable 中特定文件的句柄。使用这段代码,我能够像您期望的那样获得路径和事务上下文,
我在 SQL Server 2014 中使用 FileTable,在我的项目中首先使用 EF 代码。 当我使用这个命令时 USE [master] GO ALTER DATABASE [OnlineS
我有一个包含许多不同文档类型(.doc;.pdf;.xls 等)的文件表。 我正在编写一个小型网络(C#/.net 4)搜索应用程序。使用全文索引和文件表来查找内容的搜索效果非常好。 但是我正在努力在
我在 SQL Server 2014 中使用 FileTable,在我的项目中首先使用 EF 代码。 当我使用这个命令时 USE [master] GO ALTER DATABASE [OnlineS
我们在插入文件表时遇到问题。这是我们现在的星座,我会尽量详细的解释一下: 基本上我们有三个表: T_Document(文档的主要元数据) T_Version(文档的版本元数据) T_Content(文
我一直在设计一种使用 SQL Server FileTable 将 Lucene.NET 与 SQL Server 集成的方法原型(prototype)。使用非常方便,代码也很简单——我不需要为自定义
我有一个在 IIS 服务器上发布的 ASP.Net MVC 应用程序,在这个应用程序中我想访问存储在数据库文件表中的文件,我的意思是我正在尝试访问存储在虚拟文件表目录。注意:应用程序和数据库位于不同的
我是一名优秀的程序员,十分优秀!