views:

49

answers:

1

Hello, I have a table like:

CREATE TABLE [dbo].[MOVIES_HISTORY](
 [DATE] [datetime] NOT NULL,
 [COUNT] [int] NOT NULL CONSTRAINT [DF_MOVIES_HISTORY_COUNT]  DEFAULT ((0)),
 CONSTRAINT [PK_MOVIES_HISTORY] PRIMARY KEY CLUSTERED 
(
 [DATE] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Kinoplex.Models
{
    public class MoviesHistory
    {
        private DateTime date;
        private int count;

        public DateTime Date
        {
            get
            {
                return date;
            }
            set
            {
                date = value;
            }
        }

        public int Count
        {
            get
            {
                return count;
            }
            set
            {
                count = value;
            }
        }
    }
}

Mapping file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   namespace="Kinoplex.Models"
                   assembly="Kinoplex">

  <class name="MoviesHistory"
         dynamic-insert="true"
         dynamic-update="true"
         lazy="false"
         table="MOVIES_HISTORY">


    <id name ="Date" column="DATE" type="datetime">
    </id>

    <property name ="Count" >
      <column name="COUNT" sql-type="int" not-null="true"></column>
    </property>



  </class>
</hibernate-mapping>

Every other class is working, I only have problem with this one.

Executing query like:

IQuery query = this.session.CreateQuery("from MoviesHistory");

results in an exception:

MoviesHistory is not mapped [from MoviesHistory]

Anyone can tell me what is wrong? I suspect that id column might be wrong, but can't find anything about that.

+3  A: 

Make sure your .hbm.xml has it's build action set to Embedded Resource in your project, otherwise it won't be included in the mappings as nHibernate starts up.

Also, not positive it matters, but DateTime should have proper casing to be safe (not sure if the nHibernate parser cares anymore, it didn't at one point):

<id name="Date" column="DATE" type="DateTime">
Nick Craver
I thought it was the SQL type so I wrote datetime instead of DateTime, but that doesn't seem to matter. The problem was in the build action. Thank you very much.
kubal5003