On NH you have to create a filter definition (defines the parameters)
and the filter itself which is per entity and defines the condition.
<class ...>
<filter name="abc" condtion="col = :somearg" />
</class>
<filter-def name="abc">
<filter-param name="somearg" type="bool" />
</filter-def>
To define the filter I can rely on an attribute, but I can't see how
to map the parameters names and types on the attributes. I'm also
considering a virtual method on ARBase that the ActiveRecord could
invoke during initialization to define the filters.
On the usage side, I'm thinking about some like:
using(Post.EnableScope("recentposts"))
{
}
using(Post.EnableScope("author", author.Id))
{
}
Any ideas?
Thanks
--
Cheers,
hamilton verissimo
ham...@castlestronghold.com
http://www.castlestronghold.com/
Another option (which I think it's ugly but - maybe - would work)
[Scope("name", "condition here", new String[] { "max_age" }, new
Type[] { typeof(int) } )]
On 12/4/06, Ayende Rahien <aye...@ayende.com> wrote:
> ActiveFilter filter = new ActiveFilter("recentPosts");
> filter["date"] = DateTime.Today.AddDays(-7);
> using(Post.EnableFilter(filter))
> {
> //this is the best that I can think of.
> }
>
[Filter("recentPosts", Condition = "Date> :date"]
[Filter.Parameter("recentPosts", "date", typeof(DateTime)]
[Filter("other", Condition = "Date> :date"]
[Filter.Parameter("other", "name", typeof(String)]
On 12/4/06, Ayende Rahien <aye...@ayende.com> wrote:
> [Filter("recentPosts", Condition = "Date> :date"]
> [Filter.Parameter("date", typeof(DateTime)]
public class RecentPostsFilter : IARFilter {
public RecentPostsFilter(DateTime theDate) {}
public DateTime Date { get; set; }
public string IFilter.Name { get {return "recentPosts";}}
public Dictionary<string,object> IFilter.Parameters {}
}
[Filter(typeof(RecentPostsFilter)]
RecentPostsFilter filter = new RecentPostsFilter(DateTime.AddDays(-7);
using(Post.EnableFilter(filter) {
}
I realise this is a lot more typing - but the advantages I see are:
1. Strongly typed access to parameters.
2. Raises the concept of "filter" to it's own class - which is where
it belongs IMO. (DDD - Evans talks about Specifications.)
j.
What about:
public class RecentPostsFilter : IARFilter {
public RecentPostsFilter(DateTime theDate) {}
public DateTime Date { get; set; }
public string IFilter.Name { get {return "recentPosts";}}
public Dictionary<string,object> IFilter.Parameters {}
}
[Filter(typeof(RecentPostsFilter)]
RecentPostsFilter filter = new RecentPostsFilter(DateTime.AddDays(-7);
using(Post.EnableFilter (filter) {
}
I realise this is a lot more typing - but the advantages I see are:
1. Strongly typed access to parameters.
2. Raises the concept of "filter" to it's own class - which is where
it belongs IMO. (DDD - Evans talks about Specifications.)
j.
On 12/4/06, Hamilton Verissimo <ham...@castlestronghold.com> wrote:
>
> Cool! Were getting somewhere! :-)
>
> On 12/4/06, Ayende Rahien <aye...@ayende.com> wrote:
> > [Filter("recentPosts", Condition = "Date> :date"]
> > [Filter.Parameter (Filter = "recentPosts", "date", typeof(DateTime)]
On 12/5/06, josh robb <josh...@fastmail.fm> wrote:
>
It might make more sense to have the filtername on the attribute
rather than a static readonly member of the class. This would allow
the filter implementation to be reused more easily.
e.g.
class DateRangeFilter : IFilter {
public DateRangeFilter(DateTime from, DateTime to) {}
}
[Filter(typeof(DateRangeFilter), "activeDate")]
class Bar
[Filter(typeof(DateRangeFilter), "liveDate")]
clas Foo
j.
> > > > > > [Filter.Parameter ("recentPosts", "date", typeof(DateTime)]