NHibernate LINQ query raises "Failed to resolve property" error

I am testing LINQ with NHibernate, but have encountered some problems resolving string.length. I have the following

public class DC_Control
{
    public virtual int ID { get; private set; }
    public virtual string Name { get; set; }
    public virtual bool IsEnabled { get; set; }
    public virtual string Url { get; set; }
    public virtual string Category { get; set; }
    public virtual string Description { get; set; }
    public virtual bool RequireScriptManager { get; set; }
    public virtual string TriggerQueryString { get; set; }
    public virtual DateTime? DateAdded { get; set; }
    public virtual DateTime? DateUpdated { get; set; }
}

public class DC_ControlMap : ClassMap<DC_Control>
{
    public DC_ControlMap()
    {
        Id(x => x.ID);
        Map(x => x.Name).Length(128);
        Map(x => x.IsEnabled);
        Map(x => x.Url);
        Map(x => x.Category);
        Map(x => x.Description);
        Map(x => x.RequireScriptManager);
        Map(x => x.TriggerQueryString);
        Map(x => x.DateAdded);
        Map(x => x.DateUpdated);
    }
}

private static ISessionFactory CreateSessionFactory()
    {
        return Fluently.Configure()
            .Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008)
            .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
            .ExposeConfiguration(c => c.SetProperty("connection.connection_string", "CONNSTRING"))
            .ExposeConfiguration(c => c.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle"))
            .BuildSessionFactory();
    }

public static void test()
    {
        using (ISession session = sessionFactory.OpenSession())
        {
            var sqlQuery = session.CreateSQLQuery("select * from DC_Control  where  LEN(url) > 80").AddEntity(typeof(DC_Control)).List<DC_Control>();

            var linqQuery= session.Linq<DC_Control>().Where(c => c.Url.Length > 80).ToList();
        }
    }

In my testing method, I will first try to execute a query using SQL, this works fine. Then I want to do the same in LINQ, and this causes the following error:

NHibernate.QueryException: could not resolve property: Url.Length of: DC_Control

I searched alot for this error "failed to resolve property", but I can not understand what this means. Is it because LINQ implementation is not complete? If this is so a little disappointing, coming from Linq2Sql where it will work.

I also tried setting up the mapping to hbm.xml instead of using FluentNHibernate, but it produced the same error.

+3
1

String.Length (2.x) Linq.

Linq NHibernate 3.x ; .

session.Query session.Linq; , .

+2

Source: https://habr.com/ru/post/1744290/


All Articles