Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/Microsoft.OData.Client/ALinq/ExpressionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -578,12 +578,8 @@ internal override Expression VisitConstant(ConstantExpression c)
listExpr.Append(uriLiteral);
}

// Contains cannot be used with an empty static collection
if (listExpr.Length == 0)
{
throw new InvalidOperationException(SRResources.ALinq_ContainsNotValidOnEmptyCollection);
}

// An empty collection is translated to the empty 'in' collection literal, e.g. "Name in ()",
// which the OData query parser supports and evaluates to no matches.
listExpr.Insert(0, UriHelper.LEFTPAREN);
listExpr.Append(UriHelper.RIGHTPAREN);

Expand Down
9 changes: 0 additions & 9 deletions src/Microsoft.OData.Client/SRResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Microsoft.OData.Client/SRResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -665,9 +665,6 @@
<data name="ALinq_TypeTokenWithNoTrailingNavProp" xml:space="preserve">
<value>Found an illegal type token '{0}' without a trailing navigation property. </value>
</data>
<data name="ALinq_ContainsNotValidOnEmptyCollection" xml:space="preserve">
<value>The Contains method cannot be used with an empty collection.</value>
</data>
<data name="ALinq_AggregationMethodNotSupported" xml:space="preserve">
<value>The aggregation method '{0}' is not supported.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,33 @@ public void TranslatesEnumerableContainsWithSpecialCharactersToInOperator()
}

[Fact]
public void ThrowsForEnumerableContainsWithEmptyCollection()
public void TranslatesEnumerableContainsWithEmptyCollectionToEmptyInOperator()
{
// Arrange
var sut = new DataServiceQueryProvider(dsc);
var products = dsc.CreateQuery<Product>("Products")
.Where(product => Enumerable.Empty<string>().Contains(product.Name));

// Act
var exception = Assert.ThrowsAny<InvalidOperationException>(() => sut.Translate(products.Expression));
var queryComponents = sut.Translate(products.Expression);

// Assert
Assert.Equal(SRResources.ALinq_ContainsNotValidOnEmptyCollection, exception.Message);
Assert.Equal(@"http://root/Products?$filter=Name in ()", queryComponents.Uri.ToString());
}

[Fact]
public void ThrowsForEnumerableContainsWithEmptyEnumCollection()
public void TranslatesEnumerableContainsWithEmptyEnumCollectionToEmptyInOperator()
{
// Arrange
var sut = new DataServiceQueryProvider(dsc);
var products = dsc.CreateQuery<Product>("Products")
.Where(product => Enumerable.Empty<Color>().Contains(product.Color));

// Act
var exception = Assert.ThrowsAny<InvalidOperationException>(() => sut.Translate(products.Expression));
var queryComponents = sut.Translate(products.Expression);

// Assert
Assert.Equal(SRResources.ALinq_ContainsNotValidOnEmptyCollection, exception.Message);
Assert.Equal(@"http://root/Products?$filter=Color in ()", queryComponents.Uri.ToString());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class SRResourcesTests
[InlineData("ALinq_CollectionPropertyNotSupportedInWhere", new object[] { "Value" })]
[InlineData("ALinq_ConditionalNotSupported", new object[] { })]
[InlineData("ALinq_ConstantNotSupported", new object[] { "Value" })]
[InlineData("ALinq_ContainsNotValidOnEmptyCollection", new object[] { })]
[InlineData("ALinq_CouldNotConvert", new object[] { "Value" })]
[InlineData("ALinq_ExpressionCannotEndWithTypeAs", new object[] { "Value", "Value" })]
[InlineData("ALinq_ExpressionNotSupportedInProjection", new object[] { "Value", "Value" })]
Expand Down