|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Drawing; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Xml; |
| 7 | +using NHibernate.Bytecode.CodeDom; |
| 8 | +using NHibernate.Cfg; |
| 9 | +using NHibernate.Mapping.ByCode; |
| 10 | +using NHibernate.Test.Linq; |
| 11 | +using NUnit.Framework; |
| 12 | + |
| 13 | +namespace NHibernate.Test.VersionTest.Db |
| 14 | +{ |
| 15 | + public class ProductWithVersionAndLazyProperty |
| 16 | + { |
| 17 | + byte[] _version = null; |
| 18 | + |
| 19 | + public virtual int Id { get; set; } |
| 20 | + |
| 21 | + public virtual string Summary { get; set; } |
| 22 | + |
| 23 | + public virtual byte[] Version { get { return _version; } } |
| 24 | + } |
| 25 | + |
| 26 | + [TestFixture] |
| 27 | + public class LazyVersionTest : LinqTestCase |
| 28 | + { |
| 29 | + |
| 30 | + protected override void AddMappings(Configuration configuration) |
| 31 | + { |
| 32 | + var xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><hibernate-mapping xmlns=\"urn:nhibernate-mapping-2.2\" namespace=\"NHibernate.Test.VersionTest.Db\" assembly=\"NHibernate.Test\"><class name=\"ProductWithVersionAndLazyProperty\"><id name=\"Id\" generator=\"assigned\"/><version name=\"Version\" generated=\"always\" unsaved-value=\"null\" type=\"BinaryBlob\" access=\"nosetter.camelcase-underscore\"><column name=\"version\" not-null=\"false\" sql-type=\"timestamp\" /></version><property name=\"Summary\" lazy=\"true\"/></class></hibernate-mapping>"; |
| 33 | + var doc = new XmlDocument(); |
| 34 | + doc.LoadXml(xml); |
| 35 | + |
| 36 | + configuration.AddDocument(doc); |
| 37 | + |
| 38 | + base.AddMappings(configuration); |
| 39 | + |
| 40 | + configuration.SetProperty(NHibernate.Cfg.Environment.Hbm2ddlAuto, SchemaAutoAction.Recreate.ToString()); |
| 41 | + configuration.SetProperty(NHibernate.Cfg.Environment.FormatSql, Boolean.TrueString); |
| 42 | + configuration.SetProperty(NHibernate.Cfg.Environment.ShowSql, Boolean.TrueString); |
| 43 | + } |
| 44 | + |
| 45 | + [Test] |
| 46 | + public void CanUseVersionOnEntityWithLazyProperty() |
| 47 | + { |
| 48 | + //NH-3589 |
| 49 | + using (session.BeginTransaction()) |
| 50 | + { |
| 51 | + this.session.Save(new ProductWithVersionAndLazyProperty { Id = 1, Summary = "Testing, 1, 2, 3" }); |
| 52 | + |
| 53 | + session.Flush(); |
| 54 | + |
| 55 | + this.session.Clear(); |
| 56 | + |
| 57 | + var p = this.session.Get<ProductWithVersionAndLazyProperty>(1); |
| 58 | + |
| 59 | + p.Summary += ", 4!"; |
| 60 | + |
| 61 | + session.Flush(); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments