Hi Sergey,
I tired that so my query became:
IQuery Q = Session.CreateQuery("from Linked.Core.Domain.UserEntity as ue order by ue.Links.size asc");
Q.SetMaxResults(5);
return Q.List<UserEntity>();
but now the error is:
{"#HY000Invalid use of group function"}
and the SQL it generated is:
{select userentity0_.Id as Id, userentity0_.Name as Name4_, userentity0_.Email as Email4_, userentity0_.CreatedDate as CreatedD5_4_, userentity0_.IsAdmin as IsAdmin4_, userentity0_.TimeStamp as TimeStamp4_, userentity0_.Password as Password4_ from database.user userentity0_ order by count(*) asc}
Hmmm it seems like it isn't generating the join between the objects any idea how to fix it what i have done wrong?
Thanks heaps for your help so far!
-Alex
Here is my mapping:
Code:
<hibernate-mapping
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='urn:nhibernate-mapping-2.0'>
<meta
attribute='scope-class'>public partial</meta>
<class
name='Linked.Core.Domain.CategoryEntity, Linked.Core'
lazy='true'
table='category'>
<meta
attribute='extends'>DomainEntity<CategoryEntity, int></meta>
<cache usage='read-write' />
<id
name='Id'
column='Id'
type='Int32'
unsaved-value='0'>
<meta
attribute='gen-property'>false</meta>
<generator
class='native' />
</id>
<property
name='Name'
type='String'
column='Name'
length='150'
not-null='true' />
<property
name='Timestamp'
type='DateTime'
column='Timestamp' />
<bag
name='Links'
cascade='all'
inverse='true'>
<key
column='CategoryId' />
<one-to-many
class='Linked.Core.Domain.LinkEntity, Linked.Core' />
</bag>
<bag
name='ChildCategories'
lazy='true'>
<key
column='ParentId' />
<one-to-many
class='Linked.Core.Domain.CategoryEntity, Linked.Core' />
</bag>
<many-to-one
name='ParentCategory'
class='Linked.Core.Domain.CategoryEntity, Linked.Core'
column='ParentId'
foreign-key='Id' />
</class>
<class
name='Linked.Core.Domain.LinkEntity, Linked.Core'
lazy='true'
table='link'>
<meta
attribute='extends'>DomainEntity<LinkEntity, int></meta>
<cache usage='read-write' />
<id
name='Id'
column='Id'
type='Int32'
unsaved-value='0'>
<meta
attribute='gen-property'>False</meta>
<generator
class='native' />
</id>
<property
name='Href'
type='String'
column='Href'
length='200'
not-null='true' />
<property
name='Description'
type='String'
column='Description'
length='200'
not-null='true' />
<property
name='Name'
type='String'
column='Name'
length='200'
not-null='true' />
<property
name='Visits'
type='Int32'
column='Visits'
not-null='true' />
<property
name='AddedDate'
type='DateTime'
column='AddedDate'
not-null='true' />
<property
name='IsPublic'
type='Byte'
column='IsPublic'
not-null='true' />
<property
name='Timestamp'
type='DateTime'
column='TimeStamp' />
<bag
name='Ratings'
lazy='true'>
<key
column='LinkId' />
<one-to-many
class='Linked.Core.Domain.RatingEntity, Linked.Core' />
</bag>
<many-to-one
name='User'
class='Linked.Core.Domain.UserEntity, Linked.Core'
column='UserId'
foreign-key='Id' />
<many-to-one
name='Category'
class='Linked.Core.Domain.CategoryEntity, Linked.Core'
column='CategoryId'
foreign-key='Id' />
<idbag
name='MyUser'
table='mylink'
lazy ='true'
cascade='all'
inverse='true'>
<collection-id column="Id" type="Int32">
<generator class="increment" />
</collection-id>
<key column='LinkId' />
<many-to-many
class='Linked.Core.Domain.UserEntity, Linked.Core'
column='UserId'
/>
</idbag>
</class>
<class
name='Linked.Core.Domain.RatingEntity, Linked.Core'
lazy='true'
table='rating'>
<meta
attribute='extends'>DomainEntity<RatingEntity, int></meta>
<cache usage='read-write' />
<id
name='Id'
column='Id'
type='Int32'
unsaved-value='0'>
<meta
attribute='gen-property'>False</meta>
<generator
class='native' />
</id>
<property
name='Value'
type='Int32'
column='Value'
not-null='true' />
<many-to-one
name='User'
class='Linked.Core.Domain.UserEntity, Linked.Core'
column='UserId'
foreign-key='Id' />
<many-to-one
name='Link'
class='Linked.Core.Domain.LinkEntity, Linked.Core'
column='LinkId'
foreign-key='Id' />
</class>
<class
name='Linked.Core.Domain.UserEntity, Linked.Core'
lazy='true'
table='user'>
<meta
attribute='extends'>DomainEntity<UserEntity, int></meta>
<cache usage='read-write' />
<id
name='Id'
column='Id'
type='Int32'
unsaved-value='0'>
<meta
attribute='gen-property'>False</meta>
<generator
class='native' />
</id>
<property
name='Name'
type='String'
column='Name'
length='100'
not-null='true' />
<property
name='Email'
type='String'
column='Email'
length='100'
not-null='true' />
<property
name='Password'
type='String'
column='Password'
length='100'
not-null='true' />
<property
name='CreatedDate'
type='DateTime'
column='CreatedDate'
not-null='true' />
<property
name='IsAdmin'
type='Byte'
column='IsAdmin'
not-null='true' />
<property
name='Timestamp'
type='DateTime'
column='TimeStamp' />
<bag
name='Links'
lazy='true'>
<key
column='UserId' />
<one-to-many
class='Linked.Core.Domain.LinkEntity, Linked.Core' />
</bag>
<bag
name='Ratings'
lazy='true'>
<key
column='UserId' />
<one-to-many
class='Linked.Core.Domain.RatingEntity, Linked.Core' />
</bag>
<idbag
name='MyLinks'
table='mylink'
lazy ='true'
cascade='all'
inverse='false'
>
<collection-id column="Id" type="Int32">
<generator class="increment" />
</collection-id>
<key column='UserId' />
<many-to-many
class='Linked.Core.Domain.LinkEntity, Linked.Core'
column='LinkId'
/>
</idbag>
</class>
</hibernate-mapping>