NHibernate Criteria Transform Result

Posted by isuruceanu on Stack Overflow See other posts from Stack Overflow or by isuruceanu
Published on 2010-06-11T12:40:26Z Indexed on 2010/06/11 12:42 UTC
Read the original article Hit count: 243

Filed under:

Hi

I have an SecurityGroup entity witch has Memebers and Application properties. Application is a lookup.

So securityGroups is in many-to-many relationship with User table and one-to-many with LookupApplciation (FK)

Now I want to select all application linked to a specific user.

I have follow criteria:

 public IList<LookupApplication> GetApplicationByUser(User user)
    {
        return
            this.Session.CreateCriteria(typeof(SecurityGroup), "sg")
            .CreateAlias("Members", "u")
            .CreateAlias("Application", "al")
            .Add(Restrictions.Eq("u.Id", user.Id))

            .List<LookupApplication>();

    }

It trows an exception

The value "Edi.Advance.Core.Model.Security.SecurityGroup" is not of type "Edi.Advance.Core.Model.Lookups.LookupApplication" and cannot be used in this generic collection.
Parameter name: value

and it is right.

How can I transform the result to IList<LookupApplication>?

Thanks

© Stack Overflow or respective owner

Related posts about nhibernate