File Stream with comform. "The length of the byte[] value exceeds the length configured in the mapping/parameter." Exception.

26 views
Skip to first unread message

Ivan Korytin

unread,
Nov 15, 2013, 11:42:35 AM11/15/13
to codec...@googlegroups.com
Hello.

I have implemented all MSSQL stuff from here:

My code:
    public class TestEntity : BaseEntity
    {
        public virtual Guid ImageId { get; set; }

        public virtual Binary Image { get; set; }
    }

 class Program
    {
        static void Main(string[] args)
        {
            var factory = BuildFactory();

            using (ISession session = factory.OpenSession())
            {
                using (ITransaction tx = session.BeginTransaction())
                {
                    using (FileStream fi = File.OpenRead(@"C:\A\2013-10-31_1633.png"))
                    {
                        var photoBytes = new byte[fi.Length];
                        fi.Read(photoBytes, 0, photoBytes.Length);

                        var te = new TestEntity { Image = photoBytes };
                        session.SaveOrUpdate(te);
                        tx.Commit();
                    }
                }
            }
        }

        internal static Configuration GetConfiguration()
        {
            DomainMapper mapper = new DomainMapper();
            HbmMapping generatedMappigs = mapper.GenerateMappigs();

            var cfg = new Configuration();
            cfg.SessionFactory().Proxy.Through<NHibernate.Bytecode.DefaultProxyFactoryFactory>().Integrate.Using<MsSql2008Dialect>()
                .AutoQuoteKeywords().Connected.By<SqlClientDriver>().ByAppConfing("DBConnectionString").CreateCommands
                .ConvertingExceptionsThrough<SQLStateConverter>();
            cfg.SetProperty("show_sql", "true");
            cfg.SetProperty("format_sql", "true");
            cfg.AddDeserializedMapping(generatedMappigs, string.Empty);

            new SchemaUpdate(cfg).Execute(true, true);
            return cfg;
        }

        private static ISessionFactory BuildFactory()
        {
            Configuration cfg = GetConfiguration();
            return cfg.BuildSessionFactory();
        }
    }

How I can handle it with Conform?
Reply all
Reply to author
Forward
0 new messages