Write file to database with Nhibernate

Asked

Viewed 64 times

2

It is possible to serialize and write file in database with Nhibernate?

public virtual File Arquivo { get; set; }

He does not let map and did not want to record without using Nhibernate to follow the pattern

  • It is possible. How do you map the classes?

  • Check out this post: http://stackoverflow.com/a/26686392/2588695

  • If it is similar to Entityframework, you should map a byte[] property to the field in the database that represents this file (varbinary for example).

1 answer

4


Yes, it is possible. In C# the type has to be byte[] and not File.

Not least because File is a static class, you will never be able to use an instance of File.

In the mapping would be:

Property(x => x.Arquivo, map =>
{
    map.Type(NHibernateUtil.BinaryBlob);
    map.Length(Int32.MaxValue);
});
  • Thanks for the help, I used as follows: public virtual byte[] Arquivo { get; set; } byte[] FileSream = File.ReadAllBytes(txtArquivo.Text);
 Objeto.Arquivo = FileSream; apparently recorded normally, now I’m searching how to return this information and write the file in a directory.

  • From what you’re saying, it seems to be the case mark an answer as accepted. Here we do not write "solved" in the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.