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

Linq v Lambda #72

Open
DarthStem opened this issue Feb 1, 2018 · 3 comments
Open

Linq v Lambda #72

DarthStem opened this issue Feb 1, 2018 · 3 comments

Comments

@DarthStem
Copy link

I'm seeing unexpected behavior when querying with LINQ versus a lambda expression.

From some test code...

var fromLambda = context.Citys.FirstOrDefault(x => x.Name == cityName && x.Country.Name == countryName);
var fromLinq = (from x in context.Citys
                            where x.Name == cityName
                            where x.Country.Name == countryName
                            select x).FirstOrDefault();

Assert.IsNotNull(fromLinq);
Assert.IsNotNull(fromLambda);

fromLambda is always null but fromLinq is not null. My expectation was that they would both return the same city instance.

As background, I'm actually using a fork off of the alien-mcl/RomanticWeb fork which addressed Bug #69.

@alien-mcl
Copy link
Collaborator

Could you please elaborate more on what's behind context.Citys property? I'll try to reproduce it ASAP - it looks like the FirstOrDefault's inner predicate is not translated, or it just didn't reach the visitor.

alien-mcl added a commit to alien-mcl/RomanticWeb that referenced this issue Feb 7, 2018
@alien-mcl
Copy link
Collaborator

Hmm. I've added two tests to reproduce the issue and it seems ok (see this commit 346206e).

One is the integration tests that uses a FirstOrDefault with an inner predicate taken from another test - passes.
Another is for SPARQL query visitor that creates a SPARQL query from FirstOrDefault with an inner predicate taken from another test - passes as well.

Could please give more details, i.e. runtime environment or explain what's behind that property I mentioned earlier?

@DarthStem
Copy link
Author

DarthStem commented Feb 7, 2018

Sorry, I neglected to sanitize my example. Hopefully this is clearer?

var fromLambda = context..AsQueryable<ICity>().FirstOrDefault(x => x.Name == cityName && x.Country.Name == countryName);
var fromLinq = (from x in context.AsQueryable<ICity>()
                            where x.Name == cityName
                            where x.Country.Name == countryName
                            select x).FirstOrDefault();

Assert.IsNotNull(fromLinq);
Assert.IsNotNull(fromLambda);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants