views:

105

answers:

1

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

+2  A: 

It looks like your mapping file for the Authority entity is associating the Type property to a column named TypeFk in whatever table that the Authority entity is mapped to. For some reason, that column is not there.

It might be helpful to see your mapping files too.

Chris Dwyer
Thanks for pointing to right direction. I'm using Fluent and I had mapped ForeignKeyConvention incorrectly.
Glad to hear it. Maybe you can help a brutha out and vote up and mark answered? You know, it impresses women... and I need all the help I can get. :P
Chris Dwyer
Haha - here's a point to help you score with all the foxy girls here that get off on a guy's big rep
Berryl