Persisting Blob Streams with NHibernate

假装没事ソ 提交于 2019-12-20 14:43:00

问题


If I have a class declared as:

public class MyPersistentClass
{
     public int ID  { get; set; } 
     public Stream MyData  {get;set; }
}

How can I use NHibernate's mappings to persist the MyData property to and from the database?


回答1:


You could use a Stream using a custom type and map it according to your storage needs. But there are some issues with using the Stream object as I mention in my blog series about lazy streaming of BLOBs and CLOBs with NHibernate.

What you really need is a Blob object that in turn can create a Stream to read data from. Since Stream contains information about the position you're reading from and expects to be closed and disposed of it can create some issues when used directly in a domain model.

I would suggest that you take a look at the blog series as well as the source code of the NHibernate.Lob project. It includes various mapping options for just such a problem. A little scarcely documented so far but more is coming.



来源:https://stackoverflow.com/questions/498712/persisting-blob-streams-with-nhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!