Sql 2008 文件流与 NHibernate
我试图在 sql server 2008 中使用 Filestream 来存储用户上传的图像。
我的问题是NHibernate不会出错,但它也不会将数据保存到数据库中。 没有创建记录。
下面的 Image 类是一个自定义类(不要与 System.Drawing.Image 混淆)
public class ImageMap : ClassMap<Image>
{
public ImageMap()
{
WithTable("Images");
Id(x => x.ImageId).GeneratedBy.GuidComb().WithUnsavedValue(Guid.Empty);
Map(x => x.ImageData);
Map(x => x.Extension);
References(x => x.Owner, "UserId");
}
}
我的保存方法如下所示:
public void Save(Image image)
{
ISession session = GetSession();
session.SaveOrUpdate(image);
}
也许我保存错误,也许我的映射已关闭。 ImageData 是数据库中的 varbinary(max) 字段。
I am attempting to use Filestream in sql server 2008 to store user uploaded images.
My problem is that NHibernate will not error, but it also will not save the data into the database. No record is created.
The Image class below is a custom class (not to be confused with System.Drawing.Image)
public class ImageMap : ClassMap<Image>
{
public ImageMap()
{
WithTable("Images");
Id(x => x.ImageId).GeneratedBy.GuidComb().WithUnsavedValue(Guid.Empty);
Map(x => x.ImageData);
Map(x => x.Extension);
References(x => x.Owner, "UserId");
}
}
My method to save looks like this:
public void Save(Image image)
{
ISession session = GetSession();
session.SaveOrUpdate(image);
}
Maybe I'm saving wrong, maybe my mapping is off. ImageData is a varbinary(max) field in the database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案很简单。 我删除了对保存方法的覆盖,它自行修复了。 我们的基类已经定义了 save 方法,而我的重写完全是错误的。
The answer to this was simple. I deleted my override to the save method and it fixed itself. Our baseclass already had the save method defined and my override was just plain wrong.