I've created a data migration for a new table in my custom Orchard module. This table needs to store uploaded file data in one of the columns. Here is the migration code for the column in question (other columns removed for brevity):
SchemaBuilder.CreateTable("Attachment", table => table
.Column<byte[]>("Content", col => col.WithLength(2147483647).WithType(DbType.Binary).Unlimited())
);
I've tried adding/removing both the WithLength and the Unlimited methods, but neither stops the error from occurring. Here's the NHibernate exception:
The length of the byte[] value exceeds the length configured in the mapping/parameter.
at NHibernate.Type.AbstractBinaryType.Set(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Type.NullableType.NullSafeSet(IDbCommand cmd, Object value, Int32 index)
at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index)
EDIT: I've been playing around with things like adding a Binary Length Convention (see here: NHibernate Image Storage - The length of the byte[] value exceeds the length configured), which hasn't helped either, but it looks as if DbType.Binary has a limit of 8000 bytes, which is the ceiling that I'm hitting. From the MSDN docs: DbType.Binary - A variable-length stream of binary data ranging between 1 and 8,000 bytes. The answer would be to use SqlDbType.Image, which doesn't suffer from this restriction, but it's not usable by the Orchard Schema Builder.
EDIT 2: I forgot to add - the error occurs when I call IRepository<T>.Create()
or IRepository<T>.Update()
to create or update the domain object that is stored in the Attachment table.
Is there a way to override/extend the SchemaBuilder so that I can use SqlDbType.Image as a column type? I'm using Orchard 1.6