MakoLab / RomanticWeb

RDF-Object Mapping for the Semantic Web
http://romanticweb.net/
Other
12 stars 9 forks source link

Linq v Lambda #72

Open DarthStem opened 6 years ago

DarthStem commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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);