I'll start off by stating that I'm pretty sure I'm posting in the wrong forum here but the forum for .Net looks to be locked so bash me if you will. Anyways. So I am rather new to using NHibernate for database access and after studying its usage elsewhere in an application I am editing, I cannot seem to get it to work for me and I do not know why. Effectively, I am trying to populate an object with data from my database so that I can pull pieces in and present them to the user. The issue is that despite my syntax and code looking correct, my object remains null after query execution.
The class that is being used to represent the table in the database:
Code:
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:
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:
Code:
public class AllocateLogsForAccessPoints : IQuery<IQueryOver<AllocateLog>, AllocateLog>
{
private readonly string accessPoint;
private readonly int eventId;
public AllocateLogsForAccessPoints(int eventId, string accessPoint)
{
this.accessPoint = accessPoint;
this.eventId = eventId;
}
public IQueryOver<AllocateLog> BuildQuery(ISession session)
{
return session.QueryOver<AllocateLog>()
;//.Where(d => d.Id == eventId && d.EntryAccessPoint == accessPoint && d.DateExited != null);
}
public AllocateLog Execute(IQueryOver<AllocateLog> query)
{
return query.SingleOrDefault();
}
}
And the one line of code that I'm using to try and test if the query returns anything:
Code:
var asdf = DbQueryExecutor.ExecuteQuery(new AllocateLogsForAccessPoints(25121, (string)"South Gate"));
And I can promise you that the only possible thing that it could return from the database in that table matches the parameters that I am passing to the query; but again, it doesn't even query the database.
Anybody have any ideas?