c# - Mapping db view without Id to class model in NHibernate -
in application, use nhibernate orm , automapper mapping entities class model. as: fluent-nhibernate/wiki/auto-mapping
for tables working.
problem when try mapping db view without id field, like:
public class vtest { [notnull] public virtual aaatab aaa { get; set; } [notnull] public virtual bbbtab bbb { get; set; }
}
i create composite key :
public void override(automapping<vtest> mapping) { mapping.ignoreproperty(x => x.id); mapping.compositeid() .keyproperty(x => x.aaa.id) .keyproperty(x => x.bbb.id); }
but not working. error, becouse in db query have select id :
[genericadoexception: not execute query [ select this_.id id7_0_, this_.aaaid aaaid7_0_, this_.bbbid bbb_7_0_ [vtest] this_ ]
its possible use automapper case?
i find solutions. in compositekey must use phisical exist property in db view, create new properties:
public virtual int aaaid {get;set;} public virtual int bbbid {get;set;}
and create:
mapping.ignoreproperty(x => x.id); mapping.compositeid() .keyproperty(x => x.aaaid) .keyproperty(x => x.bbbid);
this automapping view or table without id works. (to model dbview or table, need add override function equals() , gethashcode() )
Comments
Post a Comment