The problem with a IsFavouriteItem flag on the item table, is that relationally, there's no way to enforce that only ONE item for a particular parent has that flag set. As a result, there isn't a straightforward way to map that to a single Item reference (as far as I know). I think you'd have to implement it as you've suggested, with a private list of favourite items, which should always have a maximum of one item. It would be mapped with a where clause.
As for the LastItem, I think you could do something similar again. A where clause should let you filter the items so only the last item is returned. Again it would be stored in a list of max length 1. At least this way, you don't have to touch the Items list and force it to be evaluated. I expect that there is a way to avoid having these private length-1 lists, but it would involve using some of NH's lower level hooks, such as a custom Tuplizer. And of course, as I mentioned in the previous email, a different schema would give you different mapping options. On Mon, Dec 21, 2009 at 12:47 AM, cliff vaughn <[email protected]>wrote: > Paul, > > well, ideally, i'd like to have an IsFavouriteItem on the Item table, and > instead of the IsLastItem, i'd like a way to just get the last item in the > list by date. Does that help? > > cliff > > > On Sun, Dec 20, 2009 at 5:17 AM, Paul Batum <[email protected]> wrote: > >> Hi Cliff, >> >> What schema do you want for this? You mention you don't want LastItemId >> and FavoriteItemId columns on the Parent table, so does that mean you would >> prefer IsLastItem and IsFavouriteItem flags on the Item table? Or do you >> want to use a many to many relationship and create a ParentItem table, a >> FavouriteItem table and a LastItem table (each with a ParentID and a >> ItemID)? You have to decide on a schema before we can assist you with the >> mapping. >> >> Paul Batum >> >> On Fri, Dec 18, 2009 at 8:21 AM, cliff vaughn >> <[email protected]>wrote: >> >>> Hello all, >>> >>> I've been playing around with FNH and i'm having difficulty with a >>> mapping. Suppose I have the following classes: >>> >>> class Parent >>> { >>> >>> public IList<Item> Items{get;set;} >>> public Item LastItem{get;set;} >>> public Item FavoriteItem {get;set;} >>> } >>> >>> class Item >>> { >>> public string Name {get;set;} >>> public bool IsFavorite{get;set;} >>> } >>> >>> Now, I know how to map Items using HasMany, and I know how to map >>> LastItem and FavoriteItem using References if i add a LastItemId and a >>> FavoriteItemId to the Parent table. Is there a way to get FNH to map those >>> properties without polluting Parent with extra columns. I've thought about >>> the following: >>> >>> class Parent >>> { >>> >>> public IList<Item> Items{get;set;} >>> public Item LastItem{get{return Items.LastOrDefault();}} >>> public Item FavoriteItem {get{return FavoriteItems.FirstOrDefault();}} >>> >>> private IList<Item> FavoriteItems {get;set;} >>> } >>> >>> and using a Where for the FavoriteItems mapping, but this doesn't "feel" >>> right to me. Also, now my lazy loaded Items collection with hundreds of >>> items is loaded and I don't want or need the performance hit. >>> >>> Can FNH save me? >>> >>> -- >>> thanks >>> >>> cliff >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Fluent NHibernate" group. >>> To post to this group, send email to [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<fluent-nhibernate%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/fluent-nhibernate?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Fluent NHibernate" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<fluent-nhibernate%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/fluent-nhibernate?hl=en. >> > > > > -- > thanks > > cliff > > -- > You received this message because you are subscribed to the Google Groups > "Fluent NHibernate" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<fluent-nhibernate%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/fluent-nhibernate?hl=en. > -- You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.
