c# - Nhibernate fail to delete Value Object that has null property value -


i faced sort of problem nhibernate:

when try delete component (object no id) has null value of property, operation fails because condition translated field = null instead of field null

i have rilevanzafinding object mapped component of finding:

hasmany<rilevanzafinding>(x => x.rilevanze)         .access.camelcasefield(prefix.underscore)         .table("rilevanzafinding_t045")         .keycolumn("int_t045_idfinding")         .cascade.alldeleteorphan()         .asset()         .component(fee =>         {             fee.references<rating>(x => x.rating).column("int_t045_idrating").fetch.join();             fee.map(x => x.datafine)                 .column("dte_t045_datafine")                                     .customsqltype("date");             fee.map(x => x.note)                 .column("nvc_t045_note")                 .length(100000);         });  public class finding : baseobject<finding, int> {     private icollection<rilevanzafinding> _rilevanze = new list<rilevanzafinding>();     public virtual ienumerable<rilevanzafinding> rilevanze     {                 {             return _rilevanze.toarray();         }     } }  public class rilevanzafinding : equatableobject<rilevanzafinding> {     public virtual rating rating { get; set; }     public virtual datetime? datafine{ get; set; }     public virtual string note { get; set; } } 

where equatableobject implements equals:

public override bool equals(object obj)     {         if (obj == null)             return false;          tobject other = obj tobject;          return equals(other);      }      public virtual bool equals(tobject other)     {         if (other == null)             return false;          type t = gettype();          typeinfo typeinfo = t.gettypeinfo();                     ienumerable<fieldinfo> fields = typeinfo.declaredfields.where(x => x.fieldtype.name != typeof(icollection<>).name);          foreach (fieldinfo field in fields)         {             object value1 = field.getvalue(other);             object value2 = field.getvalue(this);              if (value1 == null)             {                 if (value2 != null)                     return false;             }             else if (!value1.equals(value2))                 return false;         }         return true;     } 

now when remove rilevanza collection of finding rilevanze tis sql generated nhibernate:

nhibernate: delete rilevanzafinding_t045 int_t045_idfinding =  @p0 , dte_t045_datafine = @p1 , nvc_t045_note = @p2 , int_t045_idrating  = @p3;@p0 = 201 [type: int32 (0:0:0)], @p1 = null [type: datetime (0:0:0)], @p2 = 'gd675pfn2gtr9euj3jhpg7xfx' [type: string (1073741823:0:0)],  @p3 = 243 [type: int32 (0:0:0)] 

wich fails due "dte_t045_datafine = null" condition, since "dte_t045_datafine null"

how can make write right condition?

you cannot set.

from nhibernate reference documentation:

please note composite element mapping doesn't support null-able properties if you're using <set>. nhibernate has use each columns value identify record when deleting objects (there no separate primary key column in composite element table), not possible null values. have either use not-null properties in composite-element or choose <list>, <map>, <bag> or <idbag>.

better map entity component case, , add primary key table, in opinion. sql perform better way.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -