Skip to content

Commit

Permalink
bug in memeber init expression resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
vahid committed May 19, 2024
1 parent f6f58fe commit 8b1d276
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions 01-Core/Jinget.Core/ExpressionToSql/Internal/Select.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ private static void AddExpression(Expression e, Type t, QueryBuilder qb)
var m = (MemberExpression)e;
AddExpression(m, t, qb);
break;
case ExpressionType.MemberInit:
bool remove = false;
foreach (var item in ((MemberInitExpression)e).Bindings)
{
remove = true;
AddExpression(((MemberAssignment)item).Expression, t, qb);
qb.AddSeparator();
}
if (remove)
qb.Remove();
break;
default:
throw new NotImplementedException();
}
Expand Down
10 changes: 10 additions & 0 deletions Tests/Jinget.Core.Tests/ExpressionToSql/SqlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ public void Should_return_select_multiple_columns_from_table()
Assert.AreEqual(expectedQuery, result.query.ToString());
}

[TestMethod]
public void Should_return_select_multiple_columns_from_table_using_memberInitExpression()
{
var expectedQuery = "SELECT a.[Id], a.[FirstName] FROM [dbo].[tblTest] AS a";

var result = Sql.Select<SqlTableSample, SqlTableSample>(x => new SqlTableSample { Id = x.Id, FirstName = x.FirstName }, "tblTest").ToSql();

Assert.AreEqual(expectedQuery, result.query.ToString());
}

[TestMethod]
public void Should_return_select_all_columns_from_table()
{
Expand Down

0 comments on commit 8b1d276

Please sign in to comment.