c# - Nhibernate and MVC. Null object from query -
so rather new using nhibernate database access , after studying usage elsewhere in application editing, cannot seem work me , not know why. effectively, trying populate object data database can pull pieces in , present them user. issue despite syntax , code looking correct, object remains null after query execution.
the class being used represent table in database:
public class allocatelog { public virtual string username { get; set; } public virtual int id { get; set; } public virtual int ownerid { get; set; } public virtual int memberid { get; set; } public virtual int? resid { get; set; } public virtual string requestcomments { get; set; } public virtual datetime dateentered { get; set; } public virtual datetime? dateexited { get; set; } public virtual string entryaccesspoint { get; set; } public virtual string exitaccesspoint { get; set; } } the mapping code:
public class allocatelogoverride : iautomappingoverride<allocatelog> { public void override(automapping<allocatelog> map) { #if local_install map.schema("dbo"); #else map.schema("cred"); #endif map.table("allocate_log"); map.compositeid() .keyproperty(x => x.ownerid, "owner_id") .keyproperty(x => x.memberid, "member_id") .keyproperty(x => x.dateentered, "date_entered"); map.map(x => x.username).column("user_name"); map.map(x => x.resid).column("res_id"); map.map(x => x.requestcomments).column("request_comments"); map.map(x => x.dateexited).column("date_exited"); map.map(x => x.entryaccesspoint).column("entry_access_point"); map.map(x => x.exitaccesspoint).column("exit_access_point"); } } the query code:
public class allocatelogsforaccesspoints : iquery<iqueryover<allocatelog>, allocatelog> { private readonly string accesspoint; public allocatelogsforaccesspoints(string accesspoint) { this.accesspoint = accesspoint; } public iqueryover<allocatelog> buildquery(isession session) { return session.queryover<allocatelog>() .where(d => d.entryaccesspoint == accesspoint); } public allocatelog execute(iqueryover<allocatelog> query) { return query.singleordefault(); } } and code using test see if query return object:
var asdf = dbqueryexecutor.executequery(new allocatelogsforaccesspoints((string)"north gate")); there 1 record in database fits query row in database data in entry_access_point , string "north gate". table cred.allocate_log , of columns named correctly in mapping file. furthermore, removal of mapping file or rather commenting out not result in runtime error means me nhibernate never tries use mapping file because if try (meaning commenting out contents of file) other mapping file who's query works, runtime error. entirely stumped why object remains null after executing query runs without error. ideas? update original post if require more information.
you might try downloading application called nhprof hibernating rhinos. traces nhibernate calls , shows sql nhibernate trying run. has been godsend me in trying figure out hell nhibernate trying do.
Comments
Post a Comment