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

Filter expression translation #788

Closed
ClintGood opened this issue Jul 4, 2020 · 1 comment · Fixed by #792
Closed

Filter expression translation #788

ClintGood opened this issue Jul 4, 2020 · 1 comment · Fixed by #792

Comments

@ClintGood
Copy link

ClintGood commented Jul 4, 2020

Attempting to use JsonApiDotNetCore with SQL Server backend.
Receiving all "Teams" works fine.
Attempting to get single "Team" entity with GUID Id field.
Error received:
The LINQ expression 'DbSet
.Where(t => t.Id.Equals((object)__id_0))' could not be translated.
So the filter expression is casting to an object and this cannot be understood by the SQL server ef provider.

I figured that it was because the expression allowed for __id to be nullable, so I added a generic constraint to TId so that is was a non nullable value type (where TId: struct)
This did not make any difference.

Is this a bug with how the expression is being constructed or am I missing something.

public class Team: Identifiable<Guid>
{

    [Key]
    [Column("TeamId")]
    public override Guid Id { get; set; }

    [MaxLength(255)]
    [Required]
    [Attr]
    public string TeamName { get; set; }

    [HasMany]
    public List<TeamPlayer> TeamPlayers { get; set; }
}

...

Environment

  • JsonApiDotNetCore Version: latest master
  • Other Relevant Package Versions: ef 3.1.5
@bart-degreed
Copy link
Contributor

Hi @ClintGood, thanks for your detailed report. This looks like a bug indeed. I'm working on changes in query building where I have already fixed this. Once I have a PR, I'll add a link to here so you can track progress and confirm it fixes your issue.

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

Successfully merging a pull request may close this issue.

2 participants