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

Seeking confirmation that you can't replicate linq queries in dbfunction #11759

Closed
julielerman opened this issue Apr 20, 2018 · 3 comments
Closed
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@julielerman
Copy link

I just want to confirm that my findings are correct. It is not an issue.

If I have a scalar funciton that performs a calculation ala

CREATE FUNCTION [DaysInBattle] 
(
	@startdate date,
	@enddate date
)
RETURNS int
AS
BEGIN
	DECLARE @days int;
	select @days=datediff(D,@startdate,@enddate)+1 
   RETURN @days
END

I can replicate that logic inside a mapping which will then be used by inmemory provider.

[DbFunction(Schema = "dbo")]
       public static int DaysInBattle(DateTime start, DateTime end)
       {
           return (int)end.Subtract(start).TotalDays + 1;
       }

(hat tip to @bricelam for explaining that to me).

However if I have a function that does a query, e.g. takes in an id, queries the database, returns a scalar), there is no way to replicate that as a linq query in a mapped dbfunction, correct? At least now with the static requirement. I could test the theory out on the 2.1 preview but thought I'd just ask and not waste time if the easy answer is "nope". I just wanted to be sure with 2.0.2 that I wasn't missing something.

Thanks

@pmiddleton
Copy link
Contributor

@julielerman

I'm not quite following what you want to do exactly. Do you want to run a query vs a different linq provider when the method executes for the in-memory provider?

That you won't be able to do. There is a re-entrance issue which currently blocks nesting calls like that.

@julielerman
Copy link
Author

Thanks. yeah I even tried it with 2.1 preview. It's not logical that it would work but I don't want to put my own limitations onto your cleverness so I thought I would try. :) It's mostly so that I can state that it's not possible but I didn't want to make that statement based on an educated guess. Thanks...and closing

@pmiddleton
Copy link
Contributor

We actually tried this last year. See @ajcvickers comment on Sep 15, 2017 over on #7375

It might work in the future if PR #8865 merged in but that is currently blocked by #8864

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label May 3, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

3 participants