views:

31

answers:

1

I am new to NHibernate and have just started right now.

I have very simple table contain Id(Int primary key and auto incremented), Name(varchar(100)), Description(varchar(100))

Here is my XML

<class name="DevelopmentStep" table="DevelopmentSteps" lazy="true">
<id name="Id" type="Int32" column="Id">
</id>
<property name="Name" column="Name" type="String" length="100" not-null="false"/>
<property name="Description" column="Description" type="String" length="100" not-null="false"/>

here is how I want to get all the record

 public List<DevelopmentStep> getDevelopmentSteps()
   {
       List<DevelopmentStep> developmentStep;
       developmentStep = Repository.FindAll<DevelopmentStep>(new OrderBy("Name", Order.Asc));
       return developmentStep;
   } 

But I am getting exception

The element 'id' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List
 of possible elements expected: 'urn:nhibernate-mapping-2.2:meta urn:nhibernate-mapping-
2.2:column urn:nhibernate-mapping-2.2:generator'.

Please Advise me --- Thanks

+4  A: 

You need to specify the generator type of the id in your mapping:

<id name="Id" type="Int32" column="Id">
    <generator class="native" />
</id>
Darin Dimitrov
yes, the problem solved. thanks alot
Muhammad Akhtar
can you plz tell me one more thing, how can I make a complex queries using HQL in above method that I have posted in my question? like...select t1.ID, t2.Name from Table1 t1inner join Table2 on t1.ID = t2.IDwhere t.ID = 2
Muhammad Akhtar
I have seen example on the internet and find HQL but I am unable to use that......... public List<DevelopmentStep> getDevelopmentSteps1() { string hql = "From DevelopmentSteps d inner join table2 t2 d.id=t2.Id where d.id=IDValue"; IQuery q = session.CreateQuery(hql); }-----here I am getting issue in session
Muhammad Akhtar
@Muhammad: Put that in a new question. Reference back to this question if you want.
Michael Maddox
You need to define a class that maps to `table2` that you are trying to join. Then you could have this class as a property in the `DevelopmentSteps` class and when you try to fetch a `DevelopmentSteps` instance NHibernate will automatically generate the join query for you. There are many tutorials out there, google for `many-to-one nhibernate`.
Darin Dimitrov