Skip to content

Using Func<> for where predicate does not work #12765

@bastien-besson

Description

@bastien-besson

I'm trying to retrieve specific data from my table using a predicate. The researched sql query is as follow :
SELECT [plan].[Id] FROM [Plan] AS [plan] WHERE [plan].[IdCampagne] = 39

Plan is a table with columns

  • Id [int]
  • IdCampagne[int]
  • OtherStuff [int]

Steps to reproduce

  1. WORKING CODE
 var a = _context.Plan.AsNoTracking()
                    .Where(plan => plan.IdCampagne == 39)
                    .Select(plan => new { Id = plan.Id })
                    .ToList();

gives :
SELECT [plan].[Id] FROM [Plan] AS [plan] WHERE [plan].[IdCampagne] = 39

  1. NOT WORKING CODE
Func<Plan, bool> predicate = p => p.IdCampagne == 39;
var a = _context.Plan.AsNoTracking()
        .Where(predicate)
        .Select(plan => new { Id = plan.Id })
        .ToList();

gives :
SELECT [p].[Id], [p].[IdCampagne], [p].[OtherStuff] FROM [Plan] AS [p]

Further technical details

EF Core version: 2.1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows Server 2012 R2 Standard
IDE: Visual Studio 2017 15.7.5

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions