QueryException: could not resolve property

ptiseo's Avatar

ptiseo

26 Aug, 2010 03:29 AM via web

Okay, so I am pretty green to Fluent NHibernate, but it's been great getting to know it. However, I am hitting a stumbling point and nee help. I am attempting a Linq query trying to get Cases tied to a logged-in User, and it involves going through an obvious CaseUser table. What am I missing? (BTW, any other critique is welcome.) I am using FluentNHibernate dll v1.1.0.685, NHibernate v2.1.2.4000, NHibernate.Linq.dll v1.1.0.1001 and VS 2008.

The first three lines of the error are:

[QueryException: could not resolve property: User of: Project.Domain.Case]
NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName) +115
NHibernate.Persister.Entity.AbstractEntityPersister.ToType(String propertyName) +44
NHibernate.Loader.Criteria.EntityCriteriaInfoProvider.GetType(String relativePath) +40

The exact statement that is failing is:

public override Expression<Func<Case, bool>> MatchingCriteria
{
    get { return u => u.CaseUsers.Where(x => (x.User.UserName == this.userName)).Count() > 0; }
}

Here's the Case class. (Statement in comments is work-in-progress):

public class Case : IntegerKeyEntity
{
    private ICollection<Activity> activities = new HashSet<Activity>();
    private ICollection<CaseUser> caseUsers = new HashSet<CaseUser>();
    //private ICollection<Feature> caseFeatures = new HashSet<CaseFeature>();

    public virtual Patient Patient { get; set; }
    public virtual string CaseNb { get; set; }
    public virtual bool IsDeleted { get; set; }
    public virtual DateTime CreateDt { get; set; }
    public virtual DateTime? UpdateDt { get; set; }

    public virtual IEnumerable<Activity> Activities { get { return activities; } }
    public virtual IEnumerable<CaseUser> CaseUsers { get { return caseUsers; } }
    //public virtual IEnumerable<Feature> CaseFeatures { get { return caseFeatures; } }
}

Here's the CaseUser:

public class CaseUser : IntegerKeyEntity
{
    [EntityKeyAttribute]
    public virtual Case Case { get; set; }
    [EntityKeyAttribute]
    public virtual User User { get; set; }
    [EntityKeyAttribute]
    public virtual CaseUserType CaseUserType { get; set; }
    public virtual DateTime? FromDt { get; set; }
    public virtual DateTime? ThruDt { get; set; }
    public virtual DateTime CreateDt { get; set; }
    public virtual DateTime? UpdateDt { get; set; }
    public virtual bool? IsDeleted { get; set; }
}

And, User:

public class User : IntegerKeyEntity

{
    //private ICollection<Audit> audits = new HashSet<Audit>();
    private ICollection<CaseUser> caseUsers = new HashSet<CaseUser>();
    //private ICollection<UserContact> userContacts = new HashSet<UserContact>();
    //private ICollection<UserFeature> userFeatures = new HashSet<UserFeature>();
    private ICollection<Group> groups = new HashSet<Group>(); 

    public virtual Account Account { get; set; }
    public virtual string UserName { get; set; }
    public virtual UserType UserType { get; set; }
    public virtual string LastName { get; set; }
    public virtual string MiddleName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string Suffix { get; set; }
    public virtual byte[] Password { get; set; }
    public virtual byte[] PwdSalt { get; set; }
    public virtual byte[] Signword { get; set; }
    public virtual byte[] SignSalt { get; set; }
    public virtual DateTime CreateDt { get; set; }
    public virtual DateTime? UpdateDt { get; set; }
    public virtual DateTime FromDt { get; set; }
    public virtual DateTime? ThruDt { get; set; }
    public virtual DateTime? LastLoginDt { get; set; }
    public virtual int? FailedLoginCount { get; set; }
    public virtual DateTime? LastPwdChangeDt { get; set; }
    public virtual DateTime? LastSwdChangeDt { get; set; }
    public virtual string Comment { get; set; }
    public virtual bool IsLockedOut { get; set; }
    public virtual bool IsDeleted { get; set; }
    public virtual string PasswordQuestion { get; set; }
    public virtual string PasswordAnswer { get; set; }
    public virtual byte[] SiteKeyImage { get; set; }
    public virtual string SiteKeyCaption { get; set; }
    public virtual bool? UserMustUpdatePwd { get; set; }

    //public virtual IEnumerable<Audit> Audits { get { return _caseUserList; } }
    public virtual IEnumerable<CaseUser> CaseUsers { get { return caseUsers; } }
    //public virtual IEnumerable<UserContact> UserContacts { get { return userContacts; } }
    //public virtual IEnumerable<UserFeature> UserFeatures { get { return userFeatures; } }
    public virtual IEnumerable<Group> Groups { get { return groups; } }

    public virtual bool IsUserInactive()
    {
        DateTime today = System.DateTime.Now;
        return (IsLockedOut || IsDeleted || (today < FromDt) || (today > (ThruDt.HasValue ? ThruDt.Value : System.DateTime.MaxValue)));
    }
}

Mappings:

public class CaseMap : ClassMap<Case>
{
    public CaseMap()
    {
        Id(x => x.Id, "CaseId");

        Map(x => x.CaseNb)
            .Length(32)
            .Nullable();
        Map(x => x.IsDeleted)
            .Not.Nullable();
        Map(x => x.CreateDt)
            .Not.Nullable();
        Map(x => x.UpdateDt)
            .Nullable();

        References(x => x.Patient)
            .Class(typeof(Patient))
            .Not.Nullable()
            .Column("PatientId");

        HasMany(x => x.CaseUsers)
            .KeyColumn("CaseId")
            .Access.CamelCaseField(Prefix.None)
            .Cascade.All()
            .AsSet();
        HasMany(x => x.Activities)
            .KeyColumn("CaseId")
            .Access.CamelCaseField(Prefix.None)
            .Cascade.All()
            .AsSet();

    }
}

public class CaseUserMap : ClassMap<CaseUser>
{
    public CaseUserMap()
    {
        Id(x => x.Id, "CaseUserId");

        Map(x => x.FromDt)
            .Nullable();
        Map(x => x.ThruDt)
            .Nullable();
        Map(x => x.CreateDt)
            .Not.Nullable();
        Map(x => x.UpdateDt)
            .Nullable();
        Map(x => x.IsDeleted)
            .Nullable();

        References(x => x.Case)
            .Class(typeof(Case))
            .Not.Nullable()
            .Column("CaseId"); 
        References(x => x.User)
            .Class(typeof(User))
            .Not.Nullable()
            .Column("UserId");
        References(x => x.CaseUserType)
            .Class(typeof(CaseUserType))
            .Not.Nullable()
            .Column("CaseUserTypeId");

    }
}

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Id(x => x.Id, "UserId");

        Map(x => x.UserName)
            .Length(32)
            .Not.Nullable();
        Map(x => x.LastName)
            .Length(128)
            .Not.Nullable();
        Map(x => x.MiddleName)
            .Length(128)
            .Nullable();
        Map(x => x.FirstName)
            .Length(128)
            .Nullable();
        Map(x => x.Suffix)
            .Length(12)
            .Nullable();
        Map(x => x.Password)
            .Not.Nullable();
        Map(x => x.PwdSalt)
            .Not.Nullable();
        Map(x => x.Signword)
            .Nullable();
        Map(x => x.SignSalt)
            .Nullable();
        Map(x => x.CreateDt)
            .Not.Nullable();
        Map(x => x.UpdateDt)
            .Nullable();
        Map(x => x.FromDt)
            .Nullable();
        Map(x => x.ThruDt)
            .Nullable();
        Map(x => x.LastLoginDt)
            .Nullable();
        Map(x => x.FailedLoginCount)
            .Nullable();
        Map(x => x.LastPwdChangeDt)
            .Nullable();
        Map(x => x.LastSwdChangeDt)
            .Nullable();
        Map(x => x.Comment)
            .Length(512)
            .Nullable();
        Map(x => x.IsLockedOut)
            .Not.Nullable();
        Map(x => x.IsDeleted)
            .Not.Nullable();
        Map(x => x.PasswordQuestion)
            .Length(256)
            .Not.Nullable();
        Map(x => x.PasswordAnswer)
            .Length(128)
            .Not.Nullable();
        Map(x => x.SiteKeyImage)
            .CustomSqlType("VARBINARY(MAX)")
            .Not.Nullable();
        Map(x => x.SiteKeyCaption)
            .Length(128)
            .Not.Nullable();
        Map(x => x.UserMustUpdatePwd)
            .Not.Nullable();

        References(x => x.Account)
            .Class(typeof(Account))
            .Not.Nullable()
            .Column("AccountId"); 
        References(x => x.UserType)
            .Class(typeof(UserType))
            .Not.Nullable()
            .Column("UserTypeID");

        HasMany(x => x.CaseUsers)
            .KeyColumn("UserId")
            .Access.CamelCaseField(Prefix.None)
            .Cascade.All()
            .AsSet();

        HasManyToMany(x => x.Groups)
            .Table("UserGroup")
            .Access.CamelCaseField(Prefix.None)
            .ParentKeyColumn("UserID")
            .ChildKeyColumn("GroupID")
            .Cascade.All()
            .AsBag(); 
    }
}
  1. 2 Posted by Tommy on 21 Jan, 2011 04:42 PM

    Tommy's Avatar

    I have the same issue. Can anybody help please?

    The new switch to stack overflow for support is very sad for me. For me its very cumbersome there to find anything as everything seems very exotic there.

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    What is two plus two?