Fluent nhibernate table-per-subclass want to return items of base class type without joining to child tables -
i have classes this:
public class basicsearchresult { public virtual int itemid { get; set; } public virtual string name { get; set; } } public class advancedsearchresult : basicsearchresult { public virtual string detaileddata { get; set; } } public class basicsearchresultmap : classmap<basicsearchresult> { public basicsearchresultmap() { table("basic_search_view"); readonly(); id(x => x.itemid).column("item_id").generatedby.assigned(); map(x => x.name).column("product_name"); } } public class advancedsearchresultmap : subclassmap<advancedsearchresult> { public advancedsearchresultmap() { table("advanced_search_view"); keycolumn("item_id"); map(x => x.detaileddata).column("extra_data"); } }
where both basic & advanced views have exact same items (but vastly more horizontal data behind advanced view).
this works fine, , can retrieve database fine. issue want change want still able retrieve basicsearchresult data without joining advanced_search_view because query expensive.
in other words, want retrieve subclass when explicitly ask it. but, when ask basicsearchresult, nhibernate being overly helpful , attempting join advanced_search_view.
does know way ensure there join subclass when explicitly ask subclass?
putting way, when
session.get<basicsearchresult>(99);
it results in sql:
select this_.item_id, this_.product_name, case when this_1_.item_id not null 1 when this_.item_id not null 0 end clazz_2_ this_1_.extra_data basic_search_view this_ left outer join advanced_search_view this_1_ on this_.item_id = this_1_.item_id this_.item_id = 99
when want have:
select this_.item_id, this_.product_name basic_search_view this_ this_.item_id = 99
or - off base , should using join() kind of thing?
thanks on subject.
option 1
session.query<basicsearchresult>() .select(res => new basicsearchresult { itemid = res.itemid, name = res.name, }).tolist();
option 2
use aliastobeantransformer
option 3
write specialised mapping
Comments
Post a Comment