Skip to content

Commit

Permalink
Address comments of part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
chinadragon0515 committed May 27, 2016
1 parent ff4c36c commit 0a61ee4
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
48 changes: 26 additions & 22 deletions src/Microsoft.Restier.Core/Query/QueryExpressionContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Restier.Core/Query/QueryModelReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public class DataSourceStubModelReference : QueryModelReference
/// <param name="name">
/// The name of an entity set, singleton or function import.
/// </param>
public DataSourceStubModelReference(QueryContext context, string name)
internal DataSourceStubModelReference(QueryContext context, string name)
{
Ensure.NotNull(context, "context");
Ensure.NotNull(name, "name");
Expand Down Expand Up @@ -192,7 +192,7 @@ public class PropertyModelReference : QueryModelReference
/// <param name="propertyName">
/// The name of a property.
/// </param>
public PropertyModelReference(QueryModelReference source, string propertyName)
internal PropertyModelReference(QueryModelReference source, string propertyName)
{
Ensure.NotNull(propertyName, "propertyName");
this.propertyName = propertyName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public async Task<IHttpActionResult> Delete(CancellationToken cancellationToken)
{
throw new NotImplementedException(Resources.DeleteOnlySupportedOnEntitySet);
}

DataModificationItem deleteItem = new DataModificationItem(
entitySet.Name,
path.EdmType.GetClrType(Api),
Expand Down
3 changes: 0 additions & 3 deletions test/Microsoft.Restier.TestCommon/PublicApi.bsl
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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; }
Expand Down

0 comments on commit 0a61ee4

Please sign in to comment.