Change query filter on execute
See original GitHub issueIn 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:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
@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