c# - One-Many via NHibernate Loquacious mapping by code or xml -
i want implement one-to-many relationship between person , car, , have crud operations on both person , car. brief crud , relationships:
update
- a
person
has manycars
- crud operations on both person , car via person object.
- deleting person delete s/his cars
- ability perform crud operation on someone's cars, either via person object or car object.
is possible via orm, in particular nhibernate?
classes below:
public class personset { public virtual int id { get; set; } public virtual string name { get; set; } public virtual iset<carset> cars { get; set; } } public class carset { public virtual int id { get; set; } public virtual string name { get; set; } public virtual personset person { get; set; } }
mapping shown below:
public class personsetmap : classmapping<personset> { public personsetmap() { id(x => x.id, m=>m.generator(generators.identity)); property(x=>x.name); set(x => x.cars, c => { //c.key(k => // { // k.column("personid"); // }); c.cascade(cascade.all); c.lazy(collectionlazy.nolazy); // c.inverse(true); } , r => { r.onetomany(); } ); } } public class carsetmap : classmapping<carset> { public carsetmap() { id(x => x.id, m => m.generator(generators.identity)); property(x => x.name); manytoone(x => x.person, m => { m.column("personid"); m.cascade(cascade.none); m.notnullable(true); }); } }
the problem have if update 1 car , try save on person object, doesn't change.
update
i want find out if possible, , mapping above wrong. idea on either xml version or loquacious appreciated.
there should personid
foreign key on table car
.
i don't know if solve problem, in manytoone mapping unique , notnullable methods should applied @ column level.
manytoone(x => x.person, m => { m.column(c => { c.name("personid"); c.notnullable(true); }); m.cascade(cascade.none); });
Comments
Post a Comment