question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change query filter on execute

See original GitHub issue

In the database the type is a string, but in the code I put it to be bool, making the following configuration:

Simplified configuration:

public class ContaConfiguration : IEntityTypeConfiguration<Conta>
{
    public void Configure(EntityTypeBuilder<Conta> builder)
    {
        builder.HasKey(c => new { c.Codigo });
        builder.Property("DbImprimir");
    }
}

Simplified entity:

[System.ComponentModel.DataAnnotations.Schema.Table("conta")]
public partial class Conta
{
    [System.ComponentModel.DataAnnotations.Key()]
    [System.ComponentModel.DataAnnotations.Schema.Column("Codigo")]
    public int Codigo { get; set; }

    [System.ComponentModel.DataAnnotations.Schema.NotMapped]
    public bool? Imprimir { get; set; }

    [System.ComponentModel.DataAnnotations.Schema.Column("Imprimir")]
    private string DbImprimir { get => Imprimir.IsTrue() ? "Sim" : "Não"; set => Imprimir = value?.TryCast<string>() == "Sim"; }
}

When I put the filter below does not work, because the ‘Imprimir’ property is not mapped, does it have any before executing the query change the property to ‘DbImprimir’ in Query Linq?

using (var db = new DbContext())
{
    var test = db.Conta.Where(equipeQ => equipeQ.Imprimir == true).FirstOrDefault();
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ralmsdevelopercommented, Jan 5, 2018

Did the part I put above help with your initial question?

I suggest that when you open the problem, tell the environment that you are trying to run the tests. Example:

Further technical details

EF Core version: (found in project.csproj or packages.config) Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Operating system: IDE: (e.g. Visual Studio 2017 15.4)

By doing this, the team tries to identify more quickly or the community.

0reactions
ajcvickerscommented, Jan 9, 2018

@ErliSoares When 2.1 is released this will be possible using value conversions–that is, it will be possible to configure the bool property in the model to be converted to and from a string in the database. It should then be possible to use it in the query filter directly.

In 2.0, I don’t think that there is a way to do this because the query filter needs the actual mapped property, which has to be a string if it will be stored to the database as a string.

Closing as duplicate of #242

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to change QueryFilter run time? - asp.net core
i want to change QueryFilter run time, so i call OnModelCreating function but it doesn't work . in DbContext class : private static...
Read more >
Filter data (Power Query)
In Power Query, you can include or exclude rows according to a specific value. A filtered column contains a small filter icon in...
Read more >
Edit Query Filter
Hi, In Edit Query, am I able to: 1. Perform a Filter in Column "A" E.g. Filter to only show "5" 2. Replace...
Read more >
How to update M query parameters based on filters and slicers
Get an introduction to a new public preview feature in #Microsoft #PowerBI Dynamic M- query parameters. This new feature allows M query ......
Read more >
How to change the filter for a query at runtime?
To do this, set the initial WHERE clause to something like WHERE FALSE, or in the AppBuilder property sheet for the BROWSER deselect...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found