Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thank you, Dave, for pointing me in the right direction. One of the Date fields was nullable in the database, the other was not. I changed my class and my map to reflect that. Voila! It worked!</p> <p>Too bad the original error message didn't tell me there was an issue with a datetime field, it would've saved me some headaches.</p> <p>I made the following changes:</p> <pre><code>public class Foo { public virtual int Id { get; set; } public virtual Bar Bar{ get; set; } public virtual DateTime DateField{ get; set; } public virtual string StringField{ get; set; } public virtual Gorp Gorp{ get; set; } public virtual bool BoolField{ get; set; } public Foo() { DateField = new DateTime(1753, 1, 1); } } public class Bar { public virtual int Id { get; set; } public virtual DateTime? DateField{ get; set; } public virtual string StringField{ get; set; } public virtual ICollection&lt;Foo&gt; Foos{ get; set; } public Bar() { DateField = new DateTime(1753, 1, 1); Foos= new List&lt;Foo&gt;(); } public virtual void AddFoo(Foo foo) { foo.Bar = this; Foos.Add(foo); } } public class FooMap : ClassMap&lt;Foo&gt; { public FooMap() { Id(x =&gt; x.Id).UnsavedValue(0).GeneratedBy.Identity(); Map(x =&gt; x.DateField); Map(x =&gt; x.BoolField); Map(x =&gt; x.StringField); References(x =&gt; x.Gorp) .Column("GorpId") .Class&lt;Gorp&gt;(); References(x =&gt; x.Bar) .Column("BarId") .Not.Nullable(); } } public class BarMap : ClassMap&lt;Bar&gt; { Id(x =&gt; x.Id).UnsavedValue(0).GeneratedBy.Identity(); Map(x =&gt; x.DateField) .Nullable(); Map(x =&gt; x.StringField); HasMany&lt;Foo&gt;(x =&gt; x.Foos) .AsBag() .Cascade.SaveUpdate() .Fetch.Join() .ForeignKeyConstraintName("FK_Foo_Bar") .Inverse() .KeyColumn("BarId") .Not.KeyNullable() .Table("Foo"); } </code></pre>
 

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