Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 2.59 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why does FluentNhibernate return NullReference for existing row?
  2. table SPEC (
  3.   Special_Name varchar2 pk
  4.   Signal integer
  5.   Created_At date)
  6.  
  7. namespace App
  8. {
  9.     public class Strategy
  10.     {
  11.         public virtual string Id { get; private set; }
  12.         public virtual int Signal { get; set; }
  13.         public virtual DateTime CreatedAt { get; set; }
  14.     }
  15.  
  16.     public class StrategyMap : ClassMap<Strategy>
  17.     {
  18.         public StrategyMap()
  19.         {
  20.             this.Table("SPEC");
  21.             this.Id(x => x.Id).Column("Special_Name");
  22.             Map(x => x.Signal).Column("Signal");
  23.             Map(x => x.CreatedAt).Column("Created_At");
  24.         }
  25.     }
  26. }
  27.  
  28. namespace App.Tests
  29. {
  30.     public class StrategyMapTest
  31.     {
  32.         private ISessionFactory sessionFactory;
  33.  
  34.         public StrategyMapTest()
  35.         {
  36.             this.sessionFactory = this.CreateSessionFactory();
  37.         }
  38.  
  39.         [Fact]
  40.         public void Can_read_from_database()
  41.         {
  42.             using (var session = this.sessionFactory.OpenSession())
  43.             {
  44.                 var fromDb = session.Get<Strategy>("Foo 1");
  45.                 Assert.Equal("Foo 1", fromDb.Id);
  46.                 Assert.Equal("1", fromDb.Signal);
  47.                 Assert.Equal(new DateTime(2011,1,1), fromDb.CreatedAt);
  48.             }
  49.         }
  50.  
  51.         private ISessionFactory CreateSessionFactory()
  52.         {
  53.             return Fluently.Configure()
  54.                 .Database(OracleClientConfiguration
  55.                     .Oracle10
  56.                     .ConnectionString("connString"))
  57.                 .Mappings(m => m.FluentMappings
  58.                     .AddFromAssemblyOf<Strategy>()
  59.                     .ExportTo(@"C:logs"))
  60.                 .BuildSessionFactory();
  61.         }
  62.     }
  63. }
  64.        
  65. System.NullReferenceException: Object reference not set to an instance of an object.
  66.        
  67. <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  68.   <class xmlns="urn:nhibernate-mapping-2.2" name="App.Strategy, App, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0af8b89e104ed570" table="SPEC">
  69.     <id access="backfield" name="Id" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  70.       <column name="Special_Name" />
  71.       <generator class="assigned" />
  72.     </id>
  73.     <property name="Signal" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  74.       <column name="Signal" />
  75.     </property>
  76.     <property name="CreatedAt" type="System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  77.       <column name="Created_At" />
  78.     </property>
  79.   </class>
  80. </hibernate-mapping>