diff --git a/src/Microsoft.Restier.Core/Query/QueryExpressionContext.cs b/src/Microsoft.Restier.Core/Query/QueryExpressionContext.cs index 065ecd8e..ab206716 100644 --- a/src/Microsoft.Restier.Core/Query/QueryExpressionContext.cs +++ b/src/Microsoft.Restier.Core/Query/QueryExpressionContext.cs @@ -122,7 +122,7 @@ private static QueryModelReference ComputeQueryModelReference( var resultType = method.ReturnType.FindGenericType(typeof(IEnumerable<>)); if (sourceType == resultType) { - return new QueryModelReference(source.EntitySet,source.Type); + return new QueryModelReference(source.EntitySet, source.Type); } // source is a sequence of T1 and output is a sequence of T2 @@ -199,29 +199,33 @@ private QueryModelReference ComputeModelReference() foreach (var node in this.GetExpressionTrail()) { methodCall = node as MethodCallExpression; - if (methodCall != null) + if (methodCall == null) { - modelReference = this.GetModelReferenceForNode(node); - if (modelReference != null) + continue; + } + modelReference = this.GetModelReferenceForNode(node); + + if (modelReference == null) + { + continue; + } + var method = methodCall.Method; + var sourceType = method.GetParameters()[0] + .ParameterType.FindGenericType(typeof(IEnumerable<>)); + var resultType = method.ReturnType + .FindGenericType(typeof(IEnumerable<>)); + if (sourceType != resultType) + { + continue; + } + var typeOfT = sourceType.GetGenericArguments()[0]; + if (parameter.Type == typeOfT) + { + var collectionType = modelReference.Type as IEdmCollectionType; + if (collectionType != null) { - var method = methodCall.Method; - var sourceType = method.GetParameters()[0] - .ParameterType.FindGenericType(typeof(IEnumerable<>)); - var resultType = method.ReturnType - .FindGenericType(typeof(IEnumerable<>)); - if (sourceType == resultType) - { - var typeOfT = sourceType.GetGenericArguments()[0]; - if (parameter.Type == typeOfT) - { - var collectionType = modelReference.Type as IEdmCollectionType; - if (collectionType != null) - { - modelReference = new QueryModelReference(modelReference.EntitySet, collectionType.ElementType.Definition); - break; - } - } - } + modelReference = new QueryModelReference(modelReference.EntitySet, collectionType.ElementType.Definition); + break; } } } diff --git a/src/Microsoft.Restier.Core/Query/QueryModelReference.cs b/src/Microsoft.Restier.Core/Query/QueryModelReference.cs index 105b8e4c..185f0049 100644 --- a/src/Microsoft.Restier.Core/Query/QueryModelReference.cs +++ b/src/Microsoft.Restier.Core/Query/QueryModelReference.cs @@ -13,9 +13,9 @@ namespace Microsoft.Restier.Core.Query public class QueryModelReference { - private IEdmEntitySet edmEntitySet; + private readonly IEdmEntitySet edmEntitySet; - private IEdmType edmType; + private readonly IEdmType edmType; internal QueryModelReference() { @@ -68,7 +68,7 @@ public class DataSourceStubModelReference : QueryModelReference /// /// The name of an entity set, singleton or function import. /// - public DataSourceStubModelReference(QueryContext context, string name) + internal DataSourceStubModelReference(QueryContext context, string name) { Ensure.NotNull(context, "context"); Ensure.NotNull(name, "name"); @@ -192,7 +192,7 @@ public class PropertyModelReference : QueryModelReference /// /// The name of a property. /// - public PropertyModelReference(QueryModelReference source, string propertyName) + internal PropertyModelReference(QueryModelReference source, string propertyName) { Ensure.NotNull(propertyName, "propertyName"); this.propertyName = propertyName; diff --git a/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs b/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs index 2ed1d7bc..060f53f7 100644 --- a/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs +++ b/src/Microsoft.Restier.Publishers.OData/Query/RestierQueryBuilder.cs @@ -317,7 +317,7 @@ private void HandlePropertyAccessPathSegment(ODataPathSegment segment) private void HandleCastPathSegment(ODataPathSegment segment) { var castSegment = (CastPathSegment)segment; - Type elementType = castSegment.CastType.GetClrType(api); + var elementType = castSegment.CastType.GetClrType(api); this.currentEntityType = castSegment.CastType; this.currentType = elementType; this.queryable = ExpressionHelpers.OfType(this.queryable, elementType); diff --git a/src/Microsoft.Restier.Publishers.OData/RestierController.cs b/src/Microsoft.Restier.Publishers.OData/RestierController.cs index 3c92549b..5fc1545a 100644 --- a/src/Microsoft.Restier.Publishers.OData/RestierController.cs +++ b/src/Microsoft.Restier.Publishers.OData/RestierController.cs @@ -188,7 +188,7 @@ public async Task Delete(CancellationToken cancellationToken) { throw new NotImplementedException(Resources.DeleteOnlySupportedOnEntitySet); } - + DataModificationItem deleteItem = new DataModificationItem( entitySet.Name, path.EdmType.GetClrType(Api), diff --git a/test/Microsoft.Restier.TestCommon/PublicApi.bsl b/test/Microsoft.Restier.TestCommon/PublicApi.bsl index 8e5fe290..30b2dd4a 100644 --- a/test/Microsoft.Restier.TestCommon/PublicApi.bsl +++ b/test/Microsoft.Restier.TestCommon/PublicApi.bsl @@ -324,7 +324,6 @@ public interface Microsoft.Restier.Core.Query.IQueryExpressionSourcer { } public class Microsoft.Restier.Core.Query.DataSourceStubModelReference : Microsoft.Restier.Core.Query.QueryModelReference { - public DataSourceStubModelReference (Microsoft.Restier.Core.Query.QueryContext context, string name) public DataSourceStubModelReference (Microsoft.Restier.Core.Query.QueryContext context, string namespaceName, string name) Microsoft.OData.Edm.IEdmElement Element { public get; } @@ -333,8 +332,6 @@ public class Microsoft.Restier.Core.Query.DataSourceStubModelReference : Microso } public class Microsoft.Restier.Core.Query.PropertyModelReference : Microsoft.Restier.Core.Query.QueryModelReference { - public PropertyModelReference (Microsoft.Restier.Core.Query.QueryModelReference source, string propertyName) - Microsoft.OData.Edm.IEdmEntitySet EntitySet { public virtual get; } Microsoft.OData.Edm.IEdmProperty Property { public get; } Microsoft.Restier.Core.Query.QueryModelReference Source { [CompilerGeneratedAttribute(),]public get; }