Fluent NHibernate “Could not resolve property”

前端 未结 2 729
你的背包
你的背包 2021-01-04 01:10

I have read a lot of the questions about that same error but none since to match my exact problem. I\'m trying to access the property of an object, itself part of a root obj

2条回答
  •  礼貌的吻别
    2021-01-04 01:36

    Another explanation is that you are missing your mapping of this property or field in a NHibernateClassMapping definition. I came here about why I was getting this error based on the following scenario.

     var query = scheduleRepository.CurrentSession().Query()
                    .Where(x => x.ScheduleInfo.StartDate.Date < dateOfRun.Date);
    

    This was giving me a Could Not Resolve Property error for StartDate. This was a head scratcher, since I use this syntax all the time.

    My mapping file was the following:

    public class ScheduleInfoMapping : NHibernateClassMapping
        {
            public ScheduleInfoMapping()
            {
                DiscriminateSubClassesOnColumn("Type");
                Map(x => x.Detail).MapAsLongText();
            }
        }
    

    which was missing the StartDate. Changed to:

    public class ScheduleInfoMapping : NHibernateClassMapping
        {
            public ScheduleInfoMapping()
            {
                DiscriminateSubClassesOnColumn("Type");
                Map(x => x.Detail).MapAsLongText();
                Map(x => x.StartDate);
            }
        }
    

    Which resolved the error.

提交回复
热议问题