This repository has been archived by the owner on May 25, 2021. It is now read-only.
/
CqlObjectQuery.cs
120 lines (104 loc) · 3.15 KB
/
CqlObjectQuery.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using FluentCassandra.ObjectSerializer;
namespace FluentCassandra.Linq
{
public class CqlObjectQuery<T> : IQueryable, IQueryable<T>, IOrderedQueryable, IOrderedQueryable<T>
{
private readonly Expression _expression;
private readonly IQueryProvider _provider;
private readonly CassandraColumnFamily _family;
/// <summary>
/// Initializes a new instance of the <see cref="CqlQuery<T>"/> class.
/// </summary>
/// <param name="expression">The expression.</param>
/// <param name="provider">The provider.</param>
public CqlObjectQuery(Expression expression, IQueryProvider provider, CassandraColumnFamily family)
{
_expression = expression;
_provider = provider;
_family = family;
}
/// <summary>
///
/// </summary>
public CassandraColumnFamily Family
{
get { return _family; }
}
#region IEnumerable Members
/// <summary>
/// Returns an enumerator that iterates through a collection.
/// </summary>
/// <returns>
/// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
/// </returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#region IEnumerable<ICqlRow> Members
/// <summary>
///
/// </summary>
/// <returns></returns>
public IEnumerator<T> GetEnumerator()
{
var result = CqlQueryEvaluator.GetCql(Expression);
var fluentObjects = _family.Context.ExecuteQuery(result);
var serializer = ObjectSerializerFactory.Get(typeof(T));
return serializer
.Deserialize(fluentObjects, _family.ObjectConventions)
.OfType<T>()
.GetEnumerator();
}
#endregion
#region IQueryable Members
/// <summary>
/// Gets the type of the element(s) that are returned when the expression tree associated with this instance of <see cref="T:System.Linq.IQueryable"/> is executed.
/// </summary>
/// <value></value>
/// <returns>
/// A <see cref="T:System.Type"/> that represents the type of the element(s) that are returned when the expression tree associated with this object is executed.
/// </returns>
public virtual Type ElementType
{
get { return typeof(T); }
}
/// <summary>
/// Gets the expression tree that is associated with the instance of <see cref="T:System.Linq.IQueryable"/>.
/// </summary>
/// <value></value>
/// <returns>
/// The <see cref="T:System.Linq.Expressions.Expression"/> that is associated with this instance of <see cref="T:System.Linq.IQueryable"/>.
/// </returns>
public Expression Expression
{
get { return _expression; }
}
/// <summary>
/// Gets the query provider that is associated with this data source.
/// </summary>
/// <value></value>
/// <returns>
/// The <see cref="T:System.Linq.IQueryProvider"/> that is associated with this data source.
/// </returns>
public IQueryProvider Provider
{
get { return _provider; }
}
#endregion
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
return CqlQueryEvaluator.GetCql(Expression);
}
}
}