tags:

views:

33

answers:

1

I have a table logging web page hits. Something like: {VisitId, VisitorId, Url, Date} (The visitor ID is a GUID stored in a cookie)

I would like to create a Visitor object that has a collection of Visit objects.

class Visitor {
  public virtual Guid VisitorId { get; set; }
  public virtual IList<Visit> Visits { get; set; }
}

Rather than add another table for Visitor, can NHibernate create this object just from the collection of Visits? Ideally, I would like to write:

var visitor = session.Get<Visitor>(guidFromCookie)

And then be able to work with the Visits list and persist changes back to the DB.

(I'm using FluentNHibernate and NHibernate 3.0)

I'm new to NHibernate, but it seems the something should be possible using a custom IEntityPersister, or is this too low level and loads of work? Any suggestions would be appreciated.

A: 

When you say "create this object", do you mean retrieve? What is your reason for not having a visitor table? You could use the criteria API or hbm to load a list of visits by the guid if you don't want a visitor entity/table.

Lance Harper
Yes, I want to the retrieve the object from ISession.
Andrew Davey
I don't have a Visitor table because I don't need it really. It would just have a single Id column.
Andrew Davey
I think you will need a table if you're wanting to use "Get". Otherwise, you'll have to use some way of querying the Visit table that doesn't use a primary key (i.e. CreateCriteria, hql, etc.)
Lance Harper