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

SQL for Sqlite could not be generated #3906

Closed
jogibear9988 opened this issue Jan 11, 2023 · 6 comments · Fixed by #3907
Closed

SQL for Sqlite could not be generated #3906

jogibear9988 opened this issue Jan 11, 2023 · 6 comments · Fixed by #3907
Labels
Milestone

Comments

@jogibear9988
Copy link
Member

jogibear9988 commented Jan 11, 2023

Describe your issue

Try this code:

			var qryA = from infeed in db.GetTable<InfeedAdvicePositionDTO>()
					   select new
					   {
						   InfeedAdvicePosition = infeed,
						   CurrentQuantity = db.GetTable<InventoryResourceDTO>().Where(x => x.InfeedAdviceID == infeed.Id).Sum(x => x.Quantity),
					   };

			var qryB = from oto in qryA
					   select new
					   {
                                                         oto,
						   InfeedAddons =
							   (from ir in db.GetTable<MlogInfeedAddonsDTO>()
								where ir.Id == oto.InfeedAdvicePosition.Id
								select ir).DefaultIfEmpty().FirstOrDefault(),
					   };

			var l = qryB.First();
Exception message: System.InvalidOperationException: 'Operation is not valid due to the current state of the object.'

We get this, cause we use GetGenericMethod of a Non generic Method.

Steps to reproduce

Look at my pull request

@jogibear9988 jogibear9988 linked a pull request Jan 11, 2023 that will close this issue
@jogibear9988
Copy link
Member Author

On our server the query works for mssql server

@jogibear9988
Copy link
Member Author

image

@jogibear9988
Copy link
Member Author

@sdanyliv seems to be an error with eager loading

@jogibear9988
Copy link
Member Author

jogibear9988 commented Jan 11, 2023

I could fix it by changeing

					if (mc.IsQueryable() && mc.Method.IsGenericMethod)

here:

with this change the test works and retrieves data

@jogibear9988
Copy link
Member Author

but I don't know if it is the correct fix

@jogibear9988
Copy link
Member Author

with my change it creates following sql:

SELECT
    [oto].[Id],
    (
	    SELECT
		    Sum([x].[Quantity])
	    FROM
		    [InventoryResourceDTO] [x]
	    WHERE
		    [x].[InfeedAdviceID] = [oto].[Id]
    )
FROM
    [InfeedAdvicePositionDTO] [oto]
LIMIT @take

@MaceWindu MaceWindu added this to the 5.0.0 milestone Jan 23, 2023
@MaceWindu MaceWindu added type: bug status: has-pr There is active PR for issue labels Jan 24, 2023
MaceWindu added a commit that referenced this issue Jan 25, 2023
* test for issue #3906 - query not possible

* better test

* fix in eager loading, don't know if it is correct

Co-authored-by: MaceWindu <MaceWindu@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants