You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2017/04/18 05:39:05 UTC
[03/46] ignite git commit: IGNITE-4460 .NET: Validate From clauses in
LINQ
IGNITE-4460 .NET: Validate From clauses in LINQ
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a7d3e1bc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a7d3e1bc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a7d3e1bc
Branch: refs/heads/ignite-1561-1
Commit: a7d3e1bcdbd5a425acf1a47615432d26794df057
Parents: 727d76b
Author: Pavel Tupitsyn <pt...@apache.org>
Authored: Mon Apr 17 13:48:14 2017 +0300
Committer: Pavel Tupitsyn <pt...@apache.org>
Committed: Mon Apr 17 13:48:14 2017 +0300
----------------------------------------------------------------------
.../Cache/Query/CacheLinqTest.cs | 14 ++++++++++++++
.../Impl/CacheQueryModelVisitor.cs | 15 +++++++++++++++
2 files changed, 29 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/a7d3e1bc/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
index 0b2bb3e..876b0be 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Query/CacheLinqTest.cs
@@ -612,6 +612,20 @@ namespace Apache.Ignite.Core.Tests.Cache.Query
}
/// <summary>
+ /// Tests the SelectMany from field collection.
+ /// </summary>
+ [Test]
+ public void TestSelectManySameTable()
+ {
+ var persons = GetPersonCache().AsCacheQueryable();
+
+ // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
+ var ex = Assert.Throws<NotSupportedException>(() => persons.SelectMany(x => x.Value.Name).ToArray());
+
+ Assert.IsTrue(ex.Message.StartsWith("FROM clause must be IQueryable: from Char"));
+ }
+
+ /// <summary>
/// Tests the group by.
/// </summary>
[Test]
http://git-wip-us.apache.org/repos/asf/ignite/blob/a7d3e1bc/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
index 7cc9265..2cf4420 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Linq/Impl/CacheQueryModelVisitor.cs
@@ -348,15 +348,30 @@ namespace Apache.Ignite.Linq.Impl
base.VisitMainFromClause(fromClause, queryModel);
_builder.AppendFormat("from ");
+ ValidateFromClause(fromClause);
_aliases.AppendAsClause(_builder, fromClause).Append(" ");
foreach (var additionalFrom in queryModel.BodyClauses.OfType<AdditionalFromClause>())
{
_builder.AppendFormat(", ");
+ ValidateFromClause(additionalFrom);
_aliases.AppendAsClause(_builder, additionalFrom).Append(" ");
}
}
+ /// <summary>
+ /// Validates from clause.
+ /// </summary>
+ // ReSharper disable once UnusedParameter.Local
+ private static void ValidateFromClause(IFromClause clause)
+ {
+ // Only IQueryable can be used in FROM clause. IEnumerable is not supported.
+ if (!typeof(IQueryable).IsAssignableFrom(clause.FromExpression.Type))
+ {
+ throw new NotSupportedException("FROM clause must be IQueryable: " + clause);
+ }
+ }
+
/** <inheritdoc /> */
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods")]
public override void VisitWhereClause(WhereClause whereClause, QueryModel queryModel, int index)