gurustron commented on code in PR #1906: URL: https://github.com/apache/ignite-3/pull/1906#discussion_r1160661286
########## modules/platforms/dotnet/Apache.Ignite.Tests/Linq/LinqTests.MemberInit.cs: ########## @@ -0,0 +1,231 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Tests.Linq; + +using System; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using NUnit.Framework; + +/// <summary> +/// Linq MemberInitTests. +/// </summary> +public partial class LinqTests +{ + [Test] + public void TestSelectMemberInitInitOnly() + { + var res = PocoView.AsQueryable() + .Where(x => x.Key == 2) + .Select(x => new CustomProjectionCtorAndInit { ValueProp = x.Key, RefProp = x.Val }) + .ToArray(); + + Assert.AreEqual(1, res.Length); + Assert.AreEqual(2, res[0].ValueProp); + Assert.AreEqual("v-2", res[0].RefProp); + } + + [Test] + public void TestSelectMemberInitCtorOnly() + { + var res = PocoView.AsQueryable() + .Where(x => x.Key == 2) + .Select(x => new CustomProjectionCtorAndInit(x.Key + 42, x.Val)) + .ToArray(); + + Assert.AreEqual(1, res.Length); + Assert.AreEqual(44, res[0].Id); + Assert.AreEqual("v-2", res[0].RefProp); + } + + [Test] + public void TestSelectMemberInitSupportsInitOnlyProps() + { + var res = PocoView.AsQueryable() + .Where(x => x.Key == 2) + .Select(x => new CustomProjectionCtorAndInit + { + RefPropInitOnly = x.Val, + ValuePropInitOnly = x.Key + 2, + }) + .ToArray(); + + Assert.AreEqual(1, res.Length); + var resRow = res[0]; + Assert.AreEqual("v-2", resRow.RefPropInitOnly); + Assert.AreEqual(4, resRow.ValuePropInitOnly); + } + + [Test] + public void TestSelectMemberInitSupportsFields() + { + var res = PocoView.AsQueryable() + .Where(x => x.Key == 2) + .Select(x => new CustomProjectionCtorAndInit + { + RefField = x.Val, + ValueField = x.Key + 3 + }) + .ToArray(); + + Assert.AreEqual(1, res.Length); + var resRow = res[0]; + Assert.AreEqual("v-2", resRow.RefField); + Assert.AreEqual(5, resRow.ValueField); + } + + [Test] + public void TestSelectMemberInitCtorAndInit() + { + var res = PocoView.AsQueryable() + .Where(x => x.Key == 2) + .Select(x => new CustomProjectionCtorAndInit(x.Key) + { + RefProp = x.Val, + ValueProp = x.Key + 1, + RefPropInitOnly = x.Val, + ValuePropInitOnly = x.Key + 2, + RefField = x.Val, + ValueField = x.Key + 3 + }) + .ToArray(); + + Assert.AreEqual(1, res.Length); + var resRow = res[0]; + Assert.AreEqual(2, resRow.Id); + Assert.AreEqual("v-2", resRow.RefProp); + Assert.AreEqual(3, resRow.ValueProp); + Assert.AreEqual("v-2", resRow.RefPropInitOnly); + Assert.AreEqual(4, resRow.ValuePropInitOnly); + Assert.AreEqual("v-2", resRow.RefField); + Assert.AreEqual(5, resRow.ValueField); + } + + [Test] + public void TestSelectMemberInitFirstOrDefaultReturnsNull() Review Comment: Removed. Implementation artifact ########## modules/platforms/dotnet/Apache.Ignite/Internal/Linq/IgniteQueryExpressionVisitor.cs: ########## @@ -294,6 +294,41 @@ protected override Expression VisitMember(MemberExpression expression) return expression; } + /** <inheritdoc /> */ + protected override Expression VisitMemberInit(MemberInitExpression expression) + { + var first = true; + + if (expression.NewExpression.Arguments.Any()) + { + VisitNew(expression.NewExpression); + first = false; + } + + for (var i = 0; i < expression.Bindings.Count; i++) + { + var arg = (MemberAssignment)expression.Bindings[i]; // todo Review Comment: Removed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
