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

RC2 EF LINQ Query exception #5664

Closed
miworx opened this issue Jun 6, 2016 · 9 comments
Closed

RC2 EF LINQ Query exception #5664

miworx opened this issue Jun 6, 2016 · 9 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@miworx
Copy link

miworx commented Jun 6, 2016

I have an EF7 LINQ query on RC2 that throws the following exception. This query worked perfectly in RC1

Exception message:

An exception of type 'System.InvalidCastException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: Unable to cast object of type 'System.Linq.Expressions.Expression`1[System.Func`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[MIREQ_Portal.Models.ScreeningQuestionBlock,System.Collections.Generic.IEnumerable`1[MIREQ_Portal.Models.SiteService]],MIREQ_Portal.Models.SiteService],System.Nullable`1[System.Int32]]]' to type 'System.Linq.Expressions.ConstantExpression'.

EF Core version: 1.0.0-rc2-3002702

@divega
Copy link
Contributor

divega commented Jun 6, 2016

@miworx please provide repro model and query.

@miworx
Copy link
Author

miworx commented Jun 6, 2016

@divega
Query:

var screeningblocks = (from sb in db.ScreeningQuestionBlock
                       join ss in db.SiteService on sb.SiteService.ID equals ss.ID
                       where ss.Site.SiteName == pSiteName &&
                       ss.Service.ServiceName == pServiceName
                       orderby sb.Sequence
                       select new { sb });

The exception occurs on the following line attempting to process the query results:
foreach (var block in screeningblocks) {

Models:

    public class ScreeningQuestionBlock
    {
        public int ID { get; set; }
        public int Sequence { get; set; }
        public string Block_Text { get; set; }
        public virtual Site Site { get; set; }
        public virtual Service Service { get; set; }
        public virtual SiteService SiteService { get; set; }
        public virtual ICollection<ScreeningQuestion> ScreeningQuestion { get; set; }
    }

    public class SiteService
    {
        public int ID { get; set; }
        public int SiteID { get; set; }
        public virtual Site Site { get; set; }
        public int ServiceID { get; set; }
        public virtual Service Service { get; set; }
    }

    public class Site
    {
        public int ID { get; set; }
        public string SiteName { get; set; }

        public virtual ICollection<SiteService> SiteServices { get; set; }

    }

    public class Loc
    {
        public enum LocationRequirement {None, Left_Or_Right, Both}
    }
    public class Service
    {
        public int ID { get; set; }
        public string ServiceName { get; set; }
        public string BodyPart { get; set; }
        public string Specificity { get; set; }
        public Loc.LocationRequirement Locationrequirement { get; set; }
    }

@divega
Copy link
Contributor

divega commented Jun 6, 2016

@maumar @anpete does this look familiar? Have we fixed a bug like this recently?

@divega divega added this to the 1.0.1 milestone Jun 6, 2016
@anpete
Copy link
Contributor

anpete commented Jun 6, 2016

@divega Don't think so. Looks like complex navs.

@maumar
Copy link
Contributor

maumar commented Jun 6, 2016

might be related to #4539

@miworx
Copy link
Author

miworx commented Jun 28, 2016

@anpete Is there any update on this? Without a fix, I'm having to remain on RC1 and feeling a little handcuffed! If there's a workaround available, that would help. Thanks!

@rowanmiller rowanmiller removed the pri0 label Jul 6, 2016
@Xipooo
Copy link

Xipooo commented Jul 8, 2016

This is happening in RTM as well. I can provide an example if needed but only real difference between miworx and mine is I'm using Lambda expressions.

@flipchart
Copy link

flipchart commented Jul 28, 2016

Not sure if the same root cause, but I'm getting the same error message when using .OfType in a .Select. See gist for full repo: https://gist.github.com/flipchart/d44ae65458a845cd9e173b92df2f1c6d

EF 1.0.0

@maumar maumar modified the milestones: 1.1.0, 1.1.0-preview1 Oct 5, 2016
@maumar maumar assigned maumar and unassigned anpete Oct 5, 2016
@maumar
Copy link
Contributor

maumar commented Oct 6, 2016

This is fixed in current bits

@maumar maumar closed this as completed Oct 6, 2016
@maumar maumar added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed type-investigation labels Oct 6, 2016
@rowanmiller rowanmiller modified the milestones: 1.1.0, 1.1.0-preview1 Oct 12, 2016
@ajcvickers ajcvickers modified the milestones: 1.1.0-preview1, 1.1.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

8 participants