This repository was archived by the owner on Feb 26, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathINodeQuery.cs
More file actions
181 lines (161 loc) · 7.6 KB
/
Copy pathINodeQuery.cs
File metadata and controls
181 lines (161 loc) · 7.6 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using umbraco.NodeFactory;
namespace uComponents.Mapping
{
/// <summary>
/// Represents a query for mapped Umbraco nodes. Enumerating the
/// query gets mapped instances of every node which can be mapped to
/// <typeparamref name="TDestination"/>.
/// </summary>
/// <typeparam name="TDestination">
/// The type which queried nodes will be mapped to.
/// </typeparam>
public interface INodeQuery<TDestination> : IEnumerable<TDestination>
where TDestination : class, new()
{
/// <summary>
/// Exposes the engine being used under the hood. Useful if you want to
/// write extension methods for <see cref="INodeQuery{T}"/>.
/// </summary>
INodeMappingEngine Engine { get; }
#region Include
/// <summary>
/// Includes a relationship path in the node query.
/// </summary>
/// <param name="path">
/// The path of the relationship to include,
/// e.g. "Employers.Employees.GoldStars"
/// </param>
/// <example>
/// <code>
/// // If querying on a set of companies,
/// var myQuery = uMapper.Set<Company>()
/// .Include("Employers.Employees.GoldStars")
/// .Include("Employers.Employees.FavouriteMeals");
/// </code>
/// </example>
INodeQuery<TDestination> Include(string path);
/// <summary>
/// Includes a relationship path in the node query.
/// </summary>
/// <remarks>
/// Remarks from <c>System.Data.Entity.IQueryableExtensions.Include`2</c>:
///
/// The path expression must be composed of simple property access expressions together with calls to Select for
/// composing additional includes after including a collection proprty. Examples of possible include paths are:
/// To include a single reference: query.Include(e => e.Level1Reference)
/// To include a single collection: query.Include(e => e.Level1Collection)
/// To include a reference and then a reference one level down: query.Include(e => e.Level1Reference.Level2Reference)
/// To include a reference and then a collection one level down: query.Include(e => e.Level1Reference.Level2Collection)
/// To include a collection and then a reference one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference))
/// To include a collection and then a collection one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Collection))
/// To include a collection and then a reference one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference))
/// To include a collection and then a collection one level down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Collection))
/// To include a collection, a reference, and a reference two levels down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Reference.Level3Reference))
/// To include a collection, a collection, and a reference two levels down: query.Include(e => e.Level1Collection.Select(l1 => l1.Level2Collection.Select(l2 => l2.Level3Reference)))
/// </remarks>
/// <param name="path">
/// The path of the relationship to include, defined using
/// a lambda expression.
/// </param>
INodeQuery<TDestination> Include(Expression<Func<TDestination, object>> path);
/// <summary>
/// Includes many relationship paths in the node query
/// </summary>
/// <seealso>IncludeMany(string)</seealso>
INodeQuery<TDestination> IncludeMany(string[] paths);
/// <summary>
/// Includes many relationship paths in the node query
/// </summary>
/// <seealso>IncludeMany(Expression)</seealso>
INodeQuery<TDestination> IncludeMany(Expression<Func<TDestination, object>>[] paths);
#endregion
#region Filtering
/// <summary>
/// Filters the results to only include nodes which were mapped to
/// <typeparamref name="TDestination"/> using
/// <see cref="INodeMappingEngine.CreateMap()"/>.
///
/// In other words, does not include nodes which map to a type
/// derived from <typeparamref name="TDestination"/>.
/// </summary>
INodeQuery<TDestination> Explicit();
/// <summary>
/// Filters the results of a node query based a property.
/// </summary>
/// <typeparam name="TProperty">The property type.</typeparam>
/// <param name="property">The property to run the predicate on.</param>
/// <param name="predicate">
/// Predicate on the property for which elements should be included in
/// the result.
/// </param>
INodeQuery<TDestination> WhereProperty<TProperty>(
Expression<Func<TDestination, TProperty>> property,
Func<TProperty, bool> predicate
);
#endregion
#region Execute
/// <summary>
/// Gets a mapped instance of a specific instance of a <c>Node</c>.
/// </summary>
/// <param name="node">The node to map from.</param>
/// <returns>
/// the mapped node, or null if <paramref name="node"/> is
/// the 'empty' node or null.
/// </returns>
TDestination Map(Node node);
/// <summary>
/// Gets a mapped instance of a node by it's ID.
/// </summary>
/// <param name="id">The ID of the node to map.</param>
/// <returns>The mapped node, or null if it does not exist.</returns>
[Obsolete("Use Find() instead")]
TDestination Single(int id);
/// <summary>
/// Gets a mapped instance of a node by it's ID.
/// </summary>
/// <param name="id">The ID of the node to map.</param>
/// <returns>The mapped node, or null if it does not exist.</returns>
TDestination Find(int id);
/// <summary>
/// Gets mapped instances of nodes by their ID.
/// </summary>
/// <param name="ids">The IDs of the nodes to map.</param>
/// <returns>
/// A one-to-one collection of mapped nodes to node IDs
/// (there will be holes in the collection if some nodes
/// do not exist).
/// </returns>
IEnumerable<TDestination> Many(IEnumerable<int> ids);
/// <summary>
/// Gets mapped instances of <c>Node</c>s.
/// </summary>
/// <param name="nodes">The nodes to map.</param>
/// <returns>
/// A one-to-one collection of mapped nodes to nodes
/// (there will be holes in the collection if some nodes
/// do not exist).
/// </returns>
IEnumerable<TDestination> Many(IEnumerable<Node> nodes);
/// <summary>
/// Gets a mapped instance of the current node.
/// </summary>
/// <returns>
/// The mapped node, or null if there is no
/// current node.
/// </returns>
TDestination Current();
/// <summary>
/// Gets the specified property from each element in the result set.
/// </summary>
/// <typeparam name="TProperty">The property type.</typeparam>
/// <param name="property">The property to select.</param>
/// <returns>A collection of the selected properties.</returns>
IEnumerable<TProperty> SelectProperty<TProperty>(Expression<Func<TDestination, TProperty>> property);
#endregion
}
}