开发者

Starts with doesn't work in Linq to NHibernate query

In my repository I have:

public IQueryable<ICustomer> GetByAddress(string address)
{
    return from c in GetSession().Linq<ICustomer>()
           where c.Address.StartsWith(address)
           select c;
}

The SQL I'd like it to generate is essentially:

SELECT *
FROM Customer
WHERE address LIKE @address + '%'

However, whenever I do

var customers = myRepository.GetByAddress("123 Main Street");

I get a NullReferenceException:

System.NullReferenceException was unhandled

Message="Object reference not set to an instance of an object."

Source="NHibernate"

StackT开发者_Python百科race:

at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetEntityName(ICriteria subcriteria, String propertyName)

at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumns(String propertyName, ICriteria subcriteria)

at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumnsUsingProjection(ICriteria subcriteria, String propertyName)

Snip...

I have snipped the rest of the exception because it is quite verbose, if it would be helpful I can add it.

Why does this not work, while the exact same query except with

where c.Address == address

works perfectly fine.

Any ideas?

Edit

I'm using FluentNHibernate (where Id is a GUID and Address is a string):

public class CustomerMap: ClassMap<ICustomer>
{
    public JobMap()
    {
        Id(x => x.Id);
        ...snip...
        Map(x => x.Address).Not.Nullable();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜