I hadn't originally, because it was suggested that Futures used
MultiCriteria and that MultiCriteria throws NotSupportedException for
many of the database providers.
I have since read that Futures will fallback to immediate execution if
MultiCriteria is not supported. While this might mean that some
databases will not perform optimally, it looks to be a reasonable
tradeoff between overall performance and the amount of code I would
have to write and test to make a solid, database-agnostic
SQLQueryGenerator.
I think I'll start with Futures and re-evaluate SQLQuery generation if
I experience performance issues or have to move to a database I know
is unsupported.
Given that Future<T> is generic-only (unlike CreateCriteria), I guess
my code example becomes something like the following?
static void Main()
{
ISession session = NHUtils.GetSession();
MethodInfo futureMethod =
typeof(ICriteria).GetMethod("Future");
var theCollection = new Dictionary<Type, object>() {
{ typeof(PocoA), null },
{ typeof(PocoB), null },
{ typeof(PocoC), null },
{ typeof(PocoD), null }
};
int id = 12345;
foreach (Type t in theCollection.AllKeys) {
var entityCriteria = session.CreateCriteria(t)
.Add(Restrictions.Eq("id",
id));
MethodInfo future = futureMethod.MakeGenericMethod(t);
theCollection[t] = future.Invoke(entityCriteria);
}
foreach (Type t in theCollection.AllKeys) {
IEnumerable e = theCollection[t] as IEnumerable;
if (e != null) {
foreach (var entity in e) {
theCollection[t] = entity;
break;
}
}
}
}
On Aug 10, 1:35 pm, Mohamed Meligy <[email protected]> wrote:
> Did you consider using the Future() feature in NH?
>
> This way you get multiple queries sent to the database in the same round
> trip.
--
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.