nHibernate讲了半天保存二进制数据
我正在尝试使用 filestream 列类型和 nHibernate 将文件存储在 SQL Server 数据库中。
它似乎有效,但速度非常慢,我尝试将其更改为常规 varbinary(max) 列,但没有效果。
使用本地数据库在本地站点上进行测试...保存 ~100k 文件大约需要 5-10 秒,保存 ~5mb 文件需要 20-30 分钟。
查看 SQL 分析器,nHibernate 似乎花了那么长时间来推出插入语句,而不是数据库的问题。
当尝试提交时,它会在 iis 上增加大约 80MB 的内存,但处理器根本没有受到影响,它只是坐在那里。
在我调试 nHibernate 源代码之前,有人经历过这种情况或者有任何见解吗?
这是我的配置...
public class ProgramDocument : IDocumentFile
{
public virtual int ProgramDocumentId { get; set; }
public virtual Program Program { get; set; }
public virtual byte[] DocumentData { get; set; }
public virtual ProgramDocumentationType DocumentType { get; set; }
public virtual string MimeType { get; set; }
public virtual string FileExtension { get; set; }
public virtual ProgramPresenter ProgramPresenter { get; set; }
public virtual DateTime CreateDate { get; set; }
}
public class ProgramDocumentOverride : IAutoMappingOverride<ProgramDocument>
{
public void Override(AutoMapping<ProgramDocument> mapping)
{
mapping.Map(_ => _.DocumentData).Length(int.MaxValue).LazyLoad();
}
}
谢谢, 布莱恩·W.
I am attempting to store files in an SQL server database using the filestream column type and nHibernate.
It seems to work however it is VERY slow, I have tried changing this to just a regular varbinary(max) column and it has no effect.
Testing on a local site using a local database... saving a ~100k file takes about 5-10 seconds, saving a ~5mb file takes 20-30 minutes.
Looking at SQL profilers it seems that it is taking nHibernate that long to push out the insert statement and not an issue with the DB.
It spikes up about 80mb of memory on iis when trying to commit but the processor is not being hit at all, it just sits there.
Has anybody experienced this before or has any insights before I debug into nHibernate source?
Here is my configuration...
public class ProgramDocument : IDocumentFile
{
public virtual int ProgramDocumentId { get; set; }
public virtual Program Program { get; set; }
public virtual byte[] DocumentData { get; set; }
public virtual ProgramDocumentationType DocumentType { get; set; }
public virtual string MimeType { get; set; }
public virtual string FileExtension { get; set; }
public virtual ProgramPresenter ProgramPresenter { get; set; }
public virtual DateTime CreateDate { get; set; }
}
public class ProgramDocumentOverride : IAutoMappingOverride<ProgramDocument>
{
public void Override(AutoMapping<ProgramDocument> mapping)
{
mapping.Map(_ => _.DocumentData).Length(int.MaxValue).LazyLoad();
}
}
Thanks,
Brian W.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这个问题是由于 NH 尝试检查二进制字段是否发生变化,而这比仅仅保存需要更长的时间。我记得过去有过这样的问题,但我不记得解决方法,或者是否解决了。尝试检查 jira: https://nhibernate.jira.com/secure/Dashboard.jspa
I suspect the problem is due to the fact that NH try to check if the binary field has changes, and this take longer than just saving. I remember there was such an issue in the past and I did not remember the workaround, or if it was solved. Try to check the jira: https://nhibernate.jira.com/secure/Dashboard.jspa