3

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.

Josh
  • 16,286
  • 25
  • 113
  • 158
  • So, are you successfully using the SQL 2008 Filestream attribute with NHibernate? This is the only post I can find where someone is actually doing this. – Chris Jun 15 '10 at 21:51
  • We eventually dropped using Filestream. I believe we never could get it to work right with Nhibernate. Good luck! – Josh Jun 16 '10 at 19:34
  • You can have a look at this answer if you are interested in using the filestream http://stackoverflow.com/a/33636478/2690296 – Lee Nov 10 '15 at 18:02

1 Answers1

0

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.

public void Save(T entity)
    {
        using (ISession session = GetSession())
        using (ITransaction tx = session.BeginTransaction())
        {
            session.SaveOrUpdate(entity);
            tx.Commit();
        }
    }
Josh
  • 16,286
  • 25
  • 113
  • 158