When we first started using RavenDB we changed most of our readonly properties to methods so that they weren't persisted. Often these were calculated properties using variables that may change (such as the date). Persisting the calculated result would be of no use.
The downside of this approach is that we don't seem to be able to query on these methods, which is a pain because many of these methods represent business assertions that we then have to replicate again in our queries.
For example:
public bool IsHighProfile()
{
return Salary.To > 100000;
}
This is a business rule that states, all vacancies with salaries greater than 100,000 are high profile.
To query for high profile salaries we can't do:
session.Query<Vacancy>().Where(v => v.IsHighProfile()).ToList();
Instead we have to duplicate this rule into a query extension:
public static IQueryable<Vacancy> ThatAreHighProfile(this IQueryable<Vacancy> items)
{
}
This just smells.
So what is the recommended approach? I thought about perhaps using the specification pattern so that I'm not duplicating the business rules but am curious to see what others are doing.