Query-only properties with Fluent NHibernate

2019-07-15 07:15发布

问题:

I can't find how Nhibernate feature described in Ayende's blog works with Fluent NHibernate.

As far as I understand, I can map pseudo-field which value is a result of any hql query. Is this correct? How this feature can be used with Fluent Nhibernate? I tried google, but unsuccessful. Code samples or links to them would be much appreciated.

回答1:

According to this ticket it works:

http://code.google.com/p/fluent-nhibernate/issues/detail?id=259

There is a sample there, but I haven't tested it.

The result with Ayende's example would probaly be something like below. Note that aparently it can't be avoided to have the property representing the collection.

    public class BlogMap : ClassMap<Blog>
    {
        public BlogMap()
        {
            Id(p => p.Id);
            Map(p => p.Title
            HasMany(p => p.Posts).AsSet()
                .Where("(PostedAt >= (getdate() - 30) )")
                .Access.NoOp();
        }
    }