I’ve been struggling a long time with this problem and I can’t get it to work properly. What I want to do, is to get entries with a date earlier than a specified entry. For you to understand, I’ll to show you this code snippet:
var post = _session.Linq<PostModel>()
.Where(o => o.PostId == id)
.FirstOrDefault();
return _session.Linq<PostModel>()
.Where(o => DateTime.Compare(post.PostDate, o.PostDate) >= 0)
.ToList();
This doesn’t work! It will throw me an exception saying:
The method Compareto is not implemented.
I’ve tried implementing “IComparer” to my PostModel, but that seems not be the problem here. Although, this will work if I first convert all the entries to a list, then compare them, like this:
return _session.Linq<PostModel>().ToList()
.Where(o => DateTime.Compare(post.PostDate, o.PostDate) >= 0)
.ToList()
But to my understanding, converting all entries to a list before any cases, will cause NHibernate selecting all entries. This might not be a problem if we’re talking about a small amount of entries, but in the long term, this will waste some time.
Does anyone have any ideas?
TIA
The issue is that the NHibernate linq provider needs to convert the call to
DateTime.Compareinto SQL so it can be executed on the server. As the error states, this has not been implemented, although you may be able to change your query to:which probably will be implemented.