Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
barnuri committed Jan 6, 2025
1 parent 5887ed0 commit ca9dd9b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions LinqToKql/Provider/LinqToKqlProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,17 @@ public virtual IQueryable<TElement> CreateQuery<TElement>(Expression expression)

public virtual LinqToKqlProvider<S> Clone<S>(Expression? expression = null, bool cloneExpressionOnNull = true)
{
var kql = TableOrKQL;
expression ??= cloneExpressionOnNull ? Expression : null;
if (typeof(T) != typeof(S))
if (typeof(T) != typeof(S) && expression != null)
{
// need to move to new expression and save the old one
//kql = TranslateToKQL(expression);
//expression = null;
expression = Expression.Call(
typeof(Queryable),
nameof(Queryable.Cast),
new[] { typeof(S) },
expression
);
}
var kql = TableOrKQL;
return new(
kql,
expression,
Expand Down
4 changes: 4 additions & 0 deletions LinqToKql/Translator/LinqToKQLQueryTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ private void TranslateExpression(Expression expression, StringBuilder kqlBuilder
TranslateExpression(methodCall.Arguments[0], kqlBuilder, expression);

// Handle the current method call
if (methodCall.Method.Name == nameof(Enumerable.Cast))
{
return;
}
var translator = _translators.FirstOrDefault(t => t.LinqMethods.Contains(methodCall.Method.Name));
if (translator is null)
{
Expand Down

0 comments on commit ca9dd9b

Please sign in to comment.