-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLLBLGenProODataQueryProvider.cs
190 lines (175 loc) · 7.1 KB
/
LLBLGenProODataQueryProvider.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
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
182
183
184
185
186
187
188
189
190
//////////////////////////////////////////////////////////////////////
// Part of the OData Support Classes for LLBLGen Pro.
// LLBLGen Pro is (c) 2002-2020 Solutions Design. All rights reserved.
// http://www.llblgen.com
//////////////////////////////////////////////////////////////////////
// The OData Support Classes sourcecode is released under the following license:
// --------------------------------------------------------------------------------------------
//
// The MIT License(MIT)
//
// Copyright (c)2002-2020 Solutions Design. All rights reserved.
// https://www.llblgen.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//////////////////////////////////////////////////////////////////////
// Contributers to the code:
// - Brian Chance
// - Frans Bouma [FB]
//////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Services.Providers;
using System.Reflection;
using System.Globalization;
namespace SD.LLBLGen.Pro.ODataSupportClasses
{
/// <summary>
/// The Query provider class for the WCF Data services support.
/// </summary>
/// <typeparam name="TLinqMetaData"></typeparam>
public class LLBLGenProODataQueryProvider<TLinqMetaData> : IDataServiceQueryProvider
where TLinqMetaData : class, new()
{
#region Class Member Declarations
private LLBLGenProODataServiceMetadataProvider _metaDataProvider;
private LLBLGenProODataServiceBase<TLinqMetaData> _containingService;
private TLinqMetaData _currentDataSource;
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="LLBLGenProODataQueryProvider<TLinqMetaData>"/> class.
/// </summary>
/// <param name="metaDataProvider">The meta data provider.</param>
/// <param name="containingService">The containing service.</param>
public LLBLGenProODataQueryProvider(LLBLGenProODataServiceMetadataProvider metaDataProvider,
LLBLGenProODataServiceBase<TLinqMetaData> containingService)
{
if(metaDataProvider == null)
{
throw new ArgumentNullException(nameof(metaDataProvider));
}
if(containingService == null)
{
throw new ArgumentNullException(nameof(containingService));
}
_containingService = containingService;
_metaDataProvider = metaDataProvider;
}
#region IDataServiceQueryProvider Members
/// <summary>
/// Gets the value of the open property.
/// </summary>
/// <param name="target">Instance of the type that declares the open property.</param>
/// <param name="propertyName">Name of the open property.</param>
/// <returns>The value of the open property.</returns>
public object GetOpenPropertyValue(object target, string propertyName)
{
throw new NotImplementedException();
}
/// <summary>
/// Gets the name and values of all the properties that are defined in the given instance of an open type.
/// </summary>
/// <param name="target">Instance of the type that declares the open property.</param>
/// <returns>
/// A collection of name and values of all the open properties.
/// </returns>
public IEnumerable<KeyValuePair<string, object>> GetOpenPropertyValues(object target)
{
throw new NotImplementedException();
}
/// <summary>
/// Gets the value of the open property.
/// </summary>
/// <param name="target">Instance of the type that declares the open property.</param>
/// <param name="resourceProperty">Value for the open property.</param>
/// <returns>Value for the property.</returns>
public object GetPropertyValue(object target, ResourceProperty resourceProperty)
{
throw new NotImplementedException();
}
/// <summary>
/// Invokes the given service operation and returns the results.
/// </summary>
/// <param name="serviceOperation">Service operation to invoke.</param>
/// <param name="parameters">Values of parameters to pass to the service operation.</param>
/// <returns>
/// The result of the service operation, or a null value for a service operation that returns void.
/// </returns>
public object InvokeServiceOperation(ServiceOperation serviceOperation, object[] parameters)
{
return ((MethodInfo) serviceOperation.CustomState).Invoke(_containingService,
BindingFlags.FlattenHierarchy | BindingFlags.Instance, null, parameters,
CultureInfo.InvariantCulture);
}
/// <summary>
/// Gets the <see cref="T:System.Linq.IQueryable`1"/> that represents the container.
/// </summary>
/// <param name="resourceSet">The resource set.</param>
/// <returns>
/// An <see cref="T:System.Linq.IQueryable`1"/> that represents the resource set, or a null value if there is no resource set for the specified <paramref name="resourceSet"/>.
/// </returns>
public IQueryable GetQueryRootForResourceSet(ResourceSet resourceSet)
{
if((resourceSet==null) || (_currentDataSource==null))
{
return null;
}
var customState = resourceSet.CustomState as ResourceSetCustomState;
if(customState == null)
{
return null;
}
return customState.LinqMetaDataProperty.GetValue(_currentDataSource, null) as IQueryable;
}
/// <summary>
/// Gets the resource type for the instance that is specified by the parameter.
/// </summary>
/// <param name="target">Instance to extract a resource type from.</param>
/// <returns>
/// The <see cref="T:System.Data.Services.Providers.ResourceType"/> of the supplied object.
/// </returns>
public ResourceType GetResourceType(object target)
{
if(target == null)
{
return null;
}
return _metaDataProvider.GetResourceTypeForEntityType(target.GetType());
}
/// <summary>
/// The data source object from which data is provided.
/// </summary>
public object CurrentDataSource
{
get { return _currentDataSource; }
set { _currentDataSource = value as TLinqMetaData; }
}
/// <summary>
/// Gets a value that indicates whether null propagation is required in expression trees.
/// </summary>
public bool IsNullPropagationRequired
{
// no null propagation required, LLBLGen Pro can handle nulls in these scenarios
get { return false; }
}
#endregion
}
}