Description
Richard Thorne created an issue — 28th September 2011, 17:45:42:
I have a "Game" entity that has a static method "GetFuture" which returns an
IFutureValue<Game>
provided by nHibernate, fairly standard stuff. I recently added an optionalFunc<IQueryOver<Game, Game>, IQueryOver<Game, Game>>
parameter to allow for custom fetching strategies to be supplied to reduce roundtrips further. The code looks like this:var gameFuture = Game.GetFuture(id, query => { query = query.Fetch(x => x.CompletedActivities).Eager; if (someCondition) { query = query.Fetch(x => x.Items).Eager; } return query; });Later when I
.Remove()
an item from the "Items
" collection, the delete is not issued to the database. However if I remove the second.Fetch()
in theFunc<>
parameter so that.Items
is lazily-loaded later, the delete is issued correctly. I'm unsure if this is a bug or I'm just doing things wrong. Here are the mapping snippets for the two items:<class name="World.Game" table="Game"> <cache usage="read-write" region="Short" /> <id name="Id"> <generator class="identity" /> </id> <bag name="Items" inverse="true" cascade="all-delete-orphan" lazy="true" order-by="id ASC"> <cache usage="read-write" region="Short" /> <key column="game" /> <one-to-many class="World.Entities.Entity" /> </bag> </class> <class name="World.Entities.Entity" table="WorldContents"> <cache usage="read-write" region="Short" /> <id name="Id"> <generator class="identity" /> </id> <many-to-one name="Game" /> <property name="X" /> <property name="Y" /> </class>World.Entities.Entity has a number of joined subclasses.
I get the same problem when using the Linq
.Query<T>()
provider and when using the.QueryOver<T>()
provider.Using MySQL .NET Connector on .NET 4.
Richard Thorne added a comment — 28th September 2011, 17:50:51:
Oh I forgot to add, the GetFuture method body looks like this:
public IFutureValue<Game> GetFuture(int id, Func<IQueryOver<Game, Game>, IQueryOver<Game, Game>> modifier = null) { IQueryOver<Game, Game> query = session.QueryOver<Game>().Where(x => x.Id == id); if (modifier != null) { query = modifier(query); } return query.FutureValue(); }