-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Query: FromSql and SqlParameter issue when using with Include methods #11370
Comments
Putting this on the backlog to look at post 2.1. @punssoma Can you try using automatically generated parameters instead of using explicit SqlParameter objects? For example: public IEnumerable<UserFilterGroup> GetUserFilterGroups(UserFilterGroupSearchCriteria criteria)
{
var query = CurrentDbContext.UserFilterGroups.FromSql(
@"SELECT * FROM (" + GenerateCriteriaQuery(criteria) + @")C
ORDER BY NAME OFFSET {0} ROWS FETCH NEXT {1} ROWS ONLY",
criteria.PageNumber * criteria.Rows, criteria.Rows);
return query.Include(x => x.UserFilterValues).Include(x => x.UserFilterDefaultSettings).ToList();
} |
@ajcvickers The initial implementation was as you mentioned above. Meanwhile as a workaround i have change the code as below:
But then it would be better if it can be done using Include methods in one go. |
@punssoma - The query posted by @ajcvickers is still parametrized. When you use |
@smitpatel ok. Thanks for the info. |
In our application we start getting this bug in some cases where we using To make a formal PR with the fix I need some direction to get it correct:
|
if #12098 is implemented then this issue may not exist. |
We are also trying to pass a table-valued parameter to the SQL query, therefore we are unable to use the workaround suggested by @ajcvickers of relying on auto-generated SQL parameters:
|
@ahmadakra What happens if you use the |
Closing as fixed since #12098 fixed the underlying issue in this case. |
When using FromSql with SqlParameters and Include methods, it is failing with an exception
It seems the query is executing twice and gives error
Code
The GenerateSqlParameters function creates the parameter list
The SQl query created is :
The method is failing at the last statement while executing the query
If I remove the Include methods and just call ToList(), it is working fine
Further technical details
EF Core version: 2.0.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 7
IDE: (e.g. Visual Studio 2017 15.5.4)
The text was updated successfully, but these errors were encountered: