最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - NHibernate MismatchedTokenException - Stack Overflow

programmeradmin0浏览0评论

I have an HQL query that, every time I run it, throws Antlr.Runtime.MismatchedTokenException: 'A recognition error occurred.'. So far as I can tell, this is because I'm trying to use an entity property called End, which is a reserved keyword in HQL. Drilling down into the error shows me that when it tries to interpret the token End, it gives it a token type of 38, whereas all other identifiers in the query have token type 56.

All the solutions I can find for similar problems say that you can fix it by escaping the column name using backticks in the mapping file, and then NHibernate can magically interpret the column name properly. The trouble is, I don't have a column named End to escape - it's a custom mapped component:

public class EmploymentPeriodMap : EntityAggregateRootMap<EmploymentPeriod>
{
    public EmploymentPeriodMap()
    {
        Map(occupancy => occupancy.PersonId)
            .Not.Nullable();

        Component(x => x.EmploymentDates, dateRange =>
        {
            dateRange.Map(x => x.Start, "StartDate")
                .Not.Nullable()
                .Access.CamelCaseField(Prefix.Underscore);

            dateRange.Map(x => x.End, "EndDate")
                .Nullable()
                .Access.CamelCaseField(Prefix.Underscore);
        });
    }
}

Because HQL uses the mapped version of entities, I can't just go SELECT employmentPeriod.EndDate, but going SELECT employmentPeriod.EmploymentDates.End results in the MismatchedTokenException.

Any idea how I can manage to convince NHibernate to look at the End property, rather than assuming I'm trying to end a case statement I never started?

发布评论

评论列表(0)

  1. 暂无评论