Note that there are some explanatory texts on larger screens.

plurals
  1. PONhibernate error: The length of the byte[] value exceeds the length configured in the mapping/parameter
    primarykey
    data
    text
    <p>I want to save files using Nhibernate with Conform to MSSQL 2008.</p> <p>I`ve found article how to do it and implement everything. <a href="http://harmonypsa.blogspot.com/2013/07/using-filestream-with-sql-server-and.html" rel="nofollow">http://harmonypsa.blogspot.com/2013/07/using-filestream-with-sql-server-and.html</a></p> <p>When I run my code I get the exception: "The length of the byte[] value exceeds the length configured in the mapping/parameter." Here is my class:</p> <pre><code>public class BaseEntity { public virtual int Id { get; set; } } public class TestEntity : BaseEntity { public virtual Guid ImageId { get; set; } public virtual Binary Image { get; set; } } </code></pre> <p>My mapping:</p> <pre><code> 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&lt;NHibernate.Bytecode.DefaultProxyFactoryFactory&gt;().Integrate.Using&lt;MsSql2008Dialect&gt;() .AutoQuoteKeywords().Connected.By&lt;SqlClientDriver&gt;().ByAppConfing("DBConnectionString").CreateCommands .ConvertingExceptionsThrough&lt;SQLStateConverter&gt;(); 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(); } public HbmMapping GenerateMappigs() { IEnumerable&lt;Type&gt; domainEntities = this.GetDomainEntities(); ObjectRelationalMapper relationalMapper = new ObjectRelationalMapper(); relationalMapper.TablePerConcreteClass(domainEntities); Mapper mapper = new Mapper(relationalMapper); HbmMapping mapping = mapper.CompileMappingFor(domainEntities); //File.WriteAllText(@"d:\mappings.xml", Serialize(mapping)); return mapping; } /// &lt;summary&gt; /// Gets all objects that are inherited from EntityBase. /// &lt;/summary&gt; private IEnumerable&lt;Type&gt; GetDomainEntities() { Assembly domainAssembly = typeof(BaseEntity).Assembly; IEnumerable&lt;Type&gt; domainEntities = from t in domainAssembly.GetTypes() where t.BaseType == typeof(BaseEntity) &amp;&amp; !t.IsGenericType select t; return domainEntities; } } </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload