19 using System.Linq.Expressions;
24 namespace Deveel.Data.Linq {
28 throw new ArgumentNullException(
"table");
33 public ITable
Table {
get;
private set; }
40 return (IQueryable) Activator.CreateInstance(type,
new object[] {
this, expression});
41 }
catch (TargetInvocationException ex) {
42 throw ex.InnerException;
46 public IQueryable<TElement> CreateQuery<TElement>(Expression expression) {
50 public object Execute(Expression expression) {
51 return Execute(expression,
false);
55 private object Execute(Expression expression,
bool isEnum) {
57 if (!IsQueryOverDataSource(expression))
58 throw new InvalidProgramException(
"No query over the data source was specified.");
62 IQueryable queryResult;
68 var whereExpression = whereFinder.GetInnermostWhere(expression);
70 if (whereExpression == null) {
71 var query = builder.Build();
72 queryResult = query.Execute(elementType,
Table).AsQueryable();
74 var lambdaExpression = (LambdaExpression)((UnaryExpression)(whereExpression.Arguments[1])).Operand;
79 var query = builder.Build(lambdaExpression.Body);
80 queryResult = query.Execute(elementType,
Table).AsQueryable();
86 var newExpressionTree = treeCopier.Visit(expression);
90 return queryResult.Provider.CreateQuery(newExpressionTree);
92 return queryResult.Provider.Execute(newExpressionTree);
98 return (expression is MethodCallExpression);
101 public TResult Execute<TResult>(Expression expression) {
102 bool isEnum = (typeof(TResult).Name ==
"IEnumerable`1");
103 return (TResult) Execute(expression, isEnum);
107 throw new NotImplementedException();
object Execute(Expression expression)
object Execute(Expression expression, bool isEnum)
static bool IsQueryOverDataSource(Expression expression)
static Type GetElementType(Type seqType)
TableQueryProvider(ITable table)
static Expression PartialEval(Expression expression, Func< Expression, bool > fnCanBeEvaluated)
Performs evaluation & replacement of independent sub-trees
A TABLE object in a database.
string GetQueryText(Expression expression)
IQueryable CreateQuery(Expression expression)