Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So this is a most peculiar behavior that NHibernate is exhibiting for me here in my MVC application. The applications without error and the class mapping looks to be set up correctly but when I monitor connectivity and such for my database, I never even see a failed query or any query at all for that matter come after the query is supposedly run by my web application. Furthermore, removal of the class mapping file or rather commenting out the entire contents of the file does not result in any error when it really should. If I comment out that code for any other query that works successfully I get a runtime error.

Here is the class that represents an object from the database:
C#
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; }
}

Here is the mapping class and I can promise you that the table is cred.allocate_log and all of the column names are correct (Some of this code is commented out as I have tried using the mapping both ways, with the compositeID and without it but all of those columns make up the primary key so technically it should be with compositeID):
C#
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.Map(x => x.MemberId).Column("member_id");
            map.Map(x => x.OwnerId).Column("owner_id");
            map.Map(x => x.DateEntered).Column("date_entered");
            /*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");
        }
    }

And here is the relevant Query class code that runs without error:
C#
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();
        }
    }

Finally, the one line of code I have in a controller that I use to test whether or not I can get even a query:
C#
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?
Posted
Updated 21-May-13 7:05am
v3

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900