forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntityJoinExtensions.cs
70 lines (57 loc) · 3.05 KB
/
EntityJoinExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Linq.Expressions;
using NHibernate.Criterion;
using NHibernate.Impl;
using NHibernate.SqlCommand;
using NHibernate.Util;
namespace NHibernate
{
public static class EntityJoinExtensions
{
#region QueryOver extensions
public static TThis JoinEntityAlias<TThis, TEntity>(this TThis queryOver, Expression<Func<TEntity>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) where TThis : IQueryOver
{
CreateEntityCriteria(queryOver.UnderlyingCriteria, alias, withClause, joinType, entityName);
return queryOver;
}
public static TThis JoinEntityAlias<TThis, TEntity>(this TThis queryOver, Expression<Func<TEntity>> alias, Expression<Func<bool>> withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null) where TThis : IQueryOver
{
return JoinEntityAlias(queryOver, alias, Restrictions.Where(withClause), joinType, entityName);
}
public static IQueryOver<TRoot, TEntity> JoinEntityQueryOver<TRoot, TEntity>(this IQueryOver<TRoot> queryOver, Expression<Func<TEntity>> alias, Expression<Func<bool>> withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null)
{
return JoinEntityQueryOver(queryOver, alias, Restrictions.Where(withClause), joinType, entityName);
}
public static IQueryOver<TRoot, TEntity> JoinEntityQueryOver<TRoot, TEntity>(this IQueryOver<TRoot> queryOver, Expression<Func<TEntity>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null)
{
var q = CastOrThrow<ISupportEntityJoinQueryOver<TRoot>>(queryOver);
return q.JoinEntityQueryOver(alias, withClause, joinType, entityName);
}
#endregion QueryOver extensions
#region Criteria extensions
public static ICriteria CreateEntityAlias(this ICriteria criteria, string alias, ICriterion withClause, JoinType joinType, string entityName)
{
CreateEntityCriteria(criteria, alias, withClause, joinType, entityName);
return criteria;
}
public static ICriteria CreateEntityAlias<U>(this ICriteria criteria, Expression<Func<U>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null)
{
CreateEntityCriteria(criteria, alias, withClause, joinType, entityName);
return criteria;
}
public static ICriteria CreateEntityCriteria(this ICriteria criteria, string alias, ICriterion withClause, JoinType joinType, string entityName)
{
var c = CastOrThrow<ISupportEntityJoinCriteria>(criteria);
return c.CreateEntityCriteria(alias, withClause, joinType, entityName);
}
public static ICriteria CreateEntityCriteria<U>(this ICriteria criteria, Expression<Func<U>> alias, ICriterion withClause, JoinType joinType = JoinType.InnerJoin, string entityName = null)
{
return CreateEntityCriteria(criteria, ExpressionProcessor.FindMemberExpression(alias.Body), withClause, joinType, entityName ?? typeof(U).FullName);
}
#endregion Criteria extensions
private static T CastOrThrow<T>(object obj) where T : class
{
return ReflectHelper.CastOrThrow<T>(obj, "explicit entity joins");
}
}
}