-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Nhibernate doesn't query my database??
PostPosted: Tue May 21, 2013 11:15 am 
Newbie

Joined: Mon May 20, 2013 4:07 pm
Posts: 2
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?


Top
 Profile  
 
 Post subject: Re: Nhibernate doesn't query my database??
PostPosted: Wed May 22, 2013 8:16 am 
Newbie

Joined: Mon May 20, 2013 4:07 pm
Posts: 2
The answer to my issue was to check the namespace and location of the various files associated with the query. I had originally put one of the files in the wrong folder and so the namespace was mapped to that incorrect folder. I moved the file into the correct folder but never changed the namespace. So in the override file I had a reference to the folder the namespace said it was part of when in actuality it was not. Correcting these errors was the solution.


Top
 Profile  
 
 Post subject: Re: Nhibernate doesn't query my database??
PostPosted: Fri May 24, 2013 7:13 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hi, FYI this is the Hibernate (JAVA) forums. The NHibernate project has moved to a separate community.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.