Skip to content

Commit

Permalink
Added expanding to columns member expression.
Browse files Browse the repository at this point in the history
Corrected shared ReSharper settings to be more closer to linq2db code style.
  • Loading branch information
sdanyliv committed Feb 16, 2017
1 parent 6f99b96 commit 457c39b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Source/Linq/Builder/ExpressionBuilder.SqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,31 @@ public SqlInfo[] ConvertExpressions(IBuildContext context, Expression expression
.SelectMany(si => si)
.ToArray();
}

case ExpressionType.MemberAccess :
{
if (queryConvertFlag == ConvertFlags.All)
{
var expr = (MemberExpression) expression;
if (!MappingSchema.IsScalarType(expr.Type) && !expr.Type.IsNullable())
{
var descriptor = MappingSchema.GetEntityDescriptor(expr.Type);
if (descriptor.Columns.Count > 0)
{
return descriptor.Columns
.Where (c => c.MemberInfo.DeclaringType == expr.Type) // filtering inheritance columns
.Select(c =>
{
return ConvertExpressions(context, Expression.MakeMemberAccess(expr, c.MemberInfo), ConvertFlags.Field)
.Select(si => si.Clone(c.MemberInfo));
})
.SelectMany(si => si)
.ToArray();
}
}
}
break;
}
}

var ctx = GetContext(context, expression);
Expand Down
32 changes: 32 additions & 0 deletions Tests/Linq/Linq/IssueTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,38 @@ where t.count > 0
}
}

[Test, DataContextSource]
public void Issue115Test(string context)
{
using (var db = GetDataContext(context))
{
var qs = (from c in db.Child
join r in db.Parent on c.ParentID equals r.ParentID
where r.ParentID > 4
select c
)
.Union(from c in db.Child
join r in db.Parent on c.ParentID equals r.ParentID
where r.ParentID <= 4
select c
);

var ql = (from c in Child
join r in Parent on c.ParentID equals r.ParentID
where r.ParentID > 4
select c
)
.Union(from c in Child
join r in Parent on c.ParentID equals r.ParentID
where r.ParentID <= 4
select c
);

AreEqual(ql, qs);
}
}


[Test, DataContextSource]
public void Issue424Test1(string context)
{
Expand Down
2 changes: 2 additions & 0 deletions linq2db.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_BETWEEN_USING_GROUPS/@EntryValue">1</s:Int64>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/BLANK_LINES_INSIDE_REGION/@EntryValue">0</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/CASE_BLOCK_BRACES/@EntryValue">NEXT_LINE_SHIFTED_2</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/INITIALIZER_BRACES/@EntryValue">NEXT_LINE</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/SPACE_BEFORE_COLON_IN_CASE/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CSharpUsing/AddImportsToDeepestScope/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CSharpUsing/KeepImports/=System/@EntryIndexedValue">System</s:String>
<s:String x:Key="/Default/CodeStyle/CSharpUsing/MandatoryImports/=System/@EntryIndexedValue">System</s:String>
Expand Down

0 comments on commit 457c39b

Please sign in to comment.