-
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
.OrderBy on column 2 or more navigation properties away + .Include throws exception #3811
Comments
still repros in the current bits |
…y + .Include throws exception Problem was that in IncludeExpressionVisitor -> VisitMethodCall, when building entity accessor from a MemberExpression, we incorrectly assumed that member expression will always be one level. Fix is to add a method that will go down the Expression chain to find a ParameterExpression which is the root of the given MemberExpression
I have the same exception with a simple Where() clause. The stack strace is a bit different though :
EF 7 version RC1, SQL Server v12, I think it was working with beta8. |
…y + .Include throws exception Problem was that in IncludeExpressionVisitor -> VisitMethodCall, when building entity accessor from a MemberExpression, we incorrectly assumed that member expression will always be one level. Fix is to add a method that will go down the Expression chain to find root of the given MemberExpression. CR: Andrew
…y + .Include throws exception Problem was that in IncludeExpressionVisitor -> VisitMethodCall, when building entity accessor from a MemberExpression, we incorrectly assumed that member expression will always be one level. Fix is to add a method that will go down the Expression chain to find root of the given MemberExpression. CR: Andrew
I have also same exception, and this is my code: public IQueryable<AdImageCreative> GetAdImageCreatives()
{
var endDate = DateTime.Now.AddDays(-1);
return _adImageCreatives
.Include(x => x.AdImage)
.Include(x => x.AdImageUnit)
.Where(x => x.AdImage.IsActive && x.AdImageUnit.IsActive &&
x.EndDate > endDate && x.IsActive)
.OrderByDescending(x => x.DateUpdated);
}
[Fact]
public async Task GetAdImageCreativesTest()
{
var AdImageCreatives = await _adImageCreativeRepository.GetAdImageCreatives().ToListAsync();
Assert.NotNull(AdImageCreatives);
AdImageCreatives.ForEach(x => Console.WriteLine($"{x.AdImageUnit.Name} - {x.AdImage.Title} - {x.AdImage.Url}- {x.AdImage.Link}"));
} Error Message: If I remove Windows 10, VS 2015, SQL Server 2014, EF 7.0.0-rc1-final |
…y + .Include throws exception Problem was that in IncludeExpressionVisitor -> VisitMethodCall, when building entity accessor from a MemberExpression, we incorrectly assumed that member expression will always be one level. Fix is to add a method that will go down the Expression chain to find root of the given MemberExpression. CR: Andrew
Fixed in 8c1e269 |
@maumar Thank you, I should now what version of EF? To avoid this problem. |
@yuezhongxin it just got checked in, and will be publicly available once passes our integration tests. This should be on the nightly feed tomorrow or within a few days at most. The build number will be 16425 |
@maumar Ok, thanks! |
How do I get the latest version like EF 7 RC2 please? Do I need to fetch the repo, build and replace the ef7 packages in my project? |
@rexebin you can use this nuget.config content :
|
@adrien-constant Thank you very much, now updating my packages to the latest rc2. |
@adrien-constant After installing RC2, the project builds ok, but it would not start, not with vs 2015, not with dnx. may due to version compatibility. Is there a guidance somewhere where I could follow and start using EF7 RC2 please? I encountered a few problems with RC1, which are fixed in RC2. Thank you. |
@rexebin our guidance would be to not use our nightly builds at the moment. Things are very unstable as we move over to .NET CLI from DNX. Because of changes in package structure etc. it is hard to get a stable setup where things install, compile, and run. Things will settle down over the coming weeks. |
@rowanmiller Thank you very much. I will wait for an official release then. |
@rexebin I'm using the latest unstable version of dnx and it works well. In my case, I need the latest bug fixes. Nightly and unstable are not for everyone, but in case you want it, here are the commands you need to run to update to the a version of dnx that should work the the nightly builds :
|
@adrien-constant I did upgrade the dnx to rc2 and made sure that I used it in my project with global.json and set the rc2 to default. The project does not start. Do I need to upgrade other components to rc2 or can I just upgrade ef7 to rc2? Is the new dnx compatible with rc1-final packages like MVC? |
Still reproduce this problem |
.Include(m => m.Product.Company).AsEnumerable().Where(m => m.Project.Company.Id==1) |
@rowanmiller: Is it already recommended to use the latest nightly build to resolve this issue? |
@Carpi68 You must use VS 2015 with the latest NuGet updates (3.4.2) in order to use RC2+ |
@ErikEJ Thanks for this hint! I just updated to VS 2015 and the latest NuGet. |
You can use the NuGet feed here: https://www.myget.org/F/aspnetrelease/api/v3/index.json You should also read https://github.com/aspnet/Home/wiki/NuGet-feeds |
@ErikEJ Thank you! This may be a stupid question, but how can I use a NuGet feed with a WPF project? |
@Carpi68 Just configure the NuGet client to use the source above (you are already using NuGet if you use EF Core) |
@ErikEJ Yes, that's clear and my apology for asking stupid questions. I'm not too familiar with this task. So can you please also advise which packets I need to install via my Package Manager Console to update my EF7-rc1 to the myget/aspnetvnext? Please note: I'm not developing an ASP.NET application. I'm using EF7 for a WPF application. |
http://ef.readthedocs.org/en/latest/platforms/full-dotnet/getting-started.html (with updated package names) |
@ErikEJ I need to bother you again. I successfully upgraded to the nightly build (20539) and my project is compiling like a charm. But when I try to add a new migration I'm getting this failure Here's the complete output: c:\Users\Projects\MyProject\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20539\tools\OperationHandlers.cs(34) : c:\Users\Projects\MyProject\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20539\tools\OperationHandlers.cs(35) : >>> public virtual int Version => 0; c:\Users\Projects\MyProject\packages\Microsoft.EntityFrameworkCore.Commands.1.0.0-rc2-20539\tools\OperationHandlers.cs(36) : |
@Nikhil1292 I was able to run your scenario, slightly modified: _dbContext.Comments
.Include(c => c.Post)
.Where(c => c.Post.Blog.BlogId == true)
.ToList(); but it now yields incorrect results - I filed #5103 to track this |
@RiyasMeeran could you provide some more information about your scenario? specifically the DbContext code and entities used (Product, Company, Project and the root entity that you are trying to include) |
reopening for investigation |
@maumar can we close this one out? |
@rowanmiller yes, first example has been fixed and there is no response from the second customer about details of his scenario. |
Windows 10, VS 2015, IIS Express, SQL Server Express 2014, EF 7.0.0-rc1-final, ASP.NET 6.0.0-rc1-final
After upgrading to RC1, I am seeing an exception
Unable to cast object of type 'System.Linq.Expressions.FieldExpression' to type 'System.Linq.Expressions.ParameterExpression'.
when querying using.OrderBy
on a navigation property table 2 or more tables away from the base table, plus.Include
. This was working in beta8. I reduced the test case as much as possible to illustrate:Models:
The query that causes an exception is:
Stack trace:
Both the
.Include
and the.OrderBy
are necessary to see this exception, and the.OrderBy
must be ordering by a column at least 2 navigation properties away from the base table. For example,and
both work fine.
The text was updated successfully, but these errors were encountered: