Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FromSqlRaw not working for me in .net 6 #31457

Closed
MohammadSLM opened this issue Aug 14, 2023 · 1 comment
Closed

FromSqlRaw not working for me in .net 6 #31457

MohammadSLM opened this issue Aug 14, 2023 · 1 comment

Comments

@MohammadSLM
Copy link

MohammadSLM commented Aug 14, 2023

I have a query that is working on .net 3
but after I upgraded to .net 6 isn't working anymore
I test the query in SQL and its working but it can't be translated into Linq and give me this exception:
'FromSqlRaw' or 'FromSqlInterpolated' was called with non-composable SQL and with a query composing over it.
Consider calling 'AsEnumerable' after the method to perform the composition on the client side.

make it AsEnumerable doesn't fix it.

            string sqlCheckAllParents = @";WITH cte AS 
(
    SELECT Id, ParentId, Published, IsDeleted 
    FROM Comments h 
    WHERE Id = {0} 
    UNION ALL
    SELECT p.Id, p.ParentId, p.Published, p.IsDeleted 
    FROM
        Comments p 
        INNER JOIN
            cte c ON c.parentId = p.Id 
)
select Id from cte m where IsDeleted = 1 or Published = 0";

            var dontAllowLoadData = await _comments.FromSqlRaw(sqlCheckAllParents, parentId ?? 0).Select(x => x.Id).ToListAsync().ConfigureAwait(false);
            if (dontAllowLoadData.Any())
            {
                return new DataGridViewModel<Comment>
                {
                    Records = new List<Comment>(),
                    TotalCount = 0
                };
            }

EF Core version:
Database provider: (Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (.NET 6.0)

@bricelam
Copy link
Contributor

Duplicate of #4976

@bricelam bricelam marked this as a duplicate of #4976 Aug 28, 2023
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants