NHibernate Criteria Find by Id
Posted
by user315648
on Stack Overflow
See other posts from Stack Overflow
or by user315648
Published on 2010-04-30T16:05:19Z
Indexed on
2010/04/30
16:07 UTC
Read the original article
Hit count: 198
nhibernate
|criteria
Hello,
I have 2 entities:
public class Authority : Entity
{
[NotNull, NotEmpty]
public virtual string Name { get; set; }
[NotNull]
public virtual AuthorityType Type { get; set; }
}
public class AuthorityType : Entity
{
[NotNull, NotEmpty]
public virtual string Name { get; set; }
public virtual string Description { get; set; }
}
Now I wish to find all authorities from repository by type. I tried doing it like this:
public IList<Authority> GetAuthoritiesByType(int id)
{
ICriteria criteria = Session.CreateCriteria(typeof (Authority));
criteria.Add(Restrictions.Eq("Type.Id", id));
IList<Authority> authorities = criteria.List<Authority>();
return authorities;
}
However, I'm getting an error that something is wrong with the SQL ("could not execute query". The innerexception is following: {"Invalid column name 'TypeFk'.\r\nInvalid column name 'TypeFk'."}
Any advice ? Any other approach ?
Best wishes, Andrew
© Stack Overflow or respective owner