Actually there is no need to implement a query API over the L1 cache, as
you can do this query yourself:
-------------------------------------
public IList<T> LoadAll(bool isStateless = false)
{
IList<T> result = new List<T>();
try
{
switch (isStateless)
{
case false:
ISession session = this.GetSession();
BeginTransaction(isStateless);
// Check whether there are entities of our type in
the cache 1L:
// - If not, use ICriteria to query the database.
// - If yes, read the identity keys for our
entities, and perform a Get<T>() for each of them.
if (session.Statistics.EntityKeys.Count > 0)
{
var identifiers =
session.Statistics.EntityKeys.Where(key =>
key.EntityName == typeof(T).FullName).Select
(key => (int)key.Identifier).ToList();
if (identifiers.Count > 0)
{
result = identifiers.Select(identifier =>
session.Get<T>(identifier)).ToList();
}
else
{
ICriteria criteriaStateful =
session.CreateCriteria(typeof(T));
result = criteriaStateful.List<T>();
}
}
else
{
ICriteria criteriaStateful =
session.CreateCriteria(typeof(T));
result = criteriaStateful.List<T>();
}
if (autoCommit)
CommitTransaction();
// Note: there are no changes, therefore we don't
session.Flush().
break;
case true:
// Note: A stateless session does not feature a
cache 1L.
IStatelessSession sessionStateless =
this.OpenStatelessSession();
BeginTransaction(isStateless);
ICriteria criteriaStateless =
sessionStateless.CreateCriteria(typeof(T));
if (autoCommit)
CommitTransaction();
result = criteriaStateless.List<T>();
break;
}
}
catch (Exception ex)
{
throw new DALException(ex);
}
finally
{
if (autoCloseSession)
CloseSession();
}
return result;
}
-----------------------------------------
On Tue, Apr 10, 2012 at 12:49 PM, John T <[email protected]> wrote:
> Hi guys,
>
> I've hit a problem where we have a case that we are creating an
> entity, saving it, then Query<T>()ing for it from cache and modifying
> it. I.e. not flushing in between the initial Save() and Query().
>
> However, as I understand from a now quite old article[1] on Ayende's
> blog that this is "not possible" unless we explicity use Get()/Load().
>
> Has the situation improved since then, or is the same restriction
> still in place?
>
> Many thanks,
> John.
>
> [1]
> http://ayende.com/blog/3988/nhibernate-the-difference-between-get-load-and-querying-by-id
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" 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/nhusers?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en.