Friday, 15 March 2013

Fluent NHibernate mapping protected properties: could not resolve property: BookingNumber of: B -



Fluent NHibernate mapping protected properties: could not resolve property: BookingNumber of: B -

assume next classes:

public class { public virtual ind id { get; set; } public virtual int number { get; protected set; } } public class b : { public virtual string somevalue { get; set; } public virtual int bookingnumber { { homecoming number; } set { number = value; } } } public class c : { public virtual string someothervalue { get; set; } public virtual int accountnumber { { homecoming number; } set { number = value; } } }

as can see want expose property number under different names.

now want map a, b, c.

public class amap : classmap<a> { public amap() { id(x => x.id); map(x => x.number); } } public class bmap : subclassmap<b> { public bmap() { map(x => x.somevalue); } } public class cmap : subclassmap<c> { public cmap() { map(x => x.someothervalue); } }

with mapping can save stuff database.

however when query b or c:

session.queryover<b>().where(x => x.bookingnumber).list();

i receive error could not resolve property: bookingnumber of: b

what doing wrong?

what wrong? build query on unmapped properties.

(wrapping base of operations properties in derrived classes different names @ to the lowest degree strange), if approach needed because upper layers need diffrent names same property... then, well, ok. but, nhibernate must provided different set of information.

think query, self descriptive information, containing plenty converted sql statement.

so if utilize queryover<b>.where(x => x.bookingnumber == 1).... info (when parsing lambda expressions):

work c# object b, find property bookingnumber, find mapped representation: column name bookingnumbercolumn, take value: 1 , built query where bookingnumbercolumn = 1

in case, step number 3 fails. no column mapped bookingnumber...

solution is, @ to the lowest degree on info (nhibernate) layer, apply filter based on base of operations class a mapping

session .queryover<b>() .where(x => x.number == 1) // utilize a.number mapped property .list<b>();

but, based on experience, doing, conversion of differences in persistance (different id column name, different code column) , map them c# base of operations class or interface common, simplified structure.

more here: 16. queryover queries

nhibernate fluent-nhibernate nhibernate-mapping fluent-nhibernate-mapping

No comments:

Post a Comment