Value conversion on view only works in memory/locally
See original GitHub issueFile a bug
I have a view mapped to an entity containing a property using a value conversion from int (database) to bool (entity). The value conversion works when checking the IsEligibleToVote
property on an entity object pulled back from the view but not when querying the view (using LINQ Where
method).
When querying the view, the SQL that runs has where age = 1
instead of where age >= 18
.
Is this set up incorrectly or possibly not supported?
Include your code
// view mapping
modelBuilder
.Entity<MyEntity>(a =>
{
a.HasNoKey();
a.ToView("MyTable");
a.Property(p => p.IsEligibleToVote).HasColumName("age").HasConversion(
a => Convert.ToInt32(v),
a => Convert.ToBoolean(v >= 18)
);
});
// query
var myEntities = context.MyEntities.Where(m => m.IsEligibleToVote).ToList();
Include provider and version information
EF Core version: 5.0.5 Database provider: Microsoft.EntityFrameworkCore.SqlServer Target framework: .NET 5.0 Operating system: macOS 11 IDE: Visual Studio for Mac 8.10 Preview 2
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
how to change value in a specific memory address?
Given a valid pointer to an object in a memory address, indirect through the pointer and assign a value:
Read more >Value Conversions - EF Core
In this article Value converters allow property values to be converted when reading from or writing to the database.
Read more >Memory optimization for faster temp table and table variables
Learn about converting temporary tables, table variables, or table-valued parameters to memory-optimized tables and table variables to ...
Read more >How do I read data into R? | SAMHDA
See below for instructions on how to read and load data into R from both file ... convert variables with value labels into...
Read more >Troubleshoot Dataflow out of memory errors
To determine if your pipeline is running out of memory, use one of the following methods. On the Jobs details page, in the...
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
This particular value converter is just bad. Suppose you read a value from database from “age” column which has value of 25. The converter will convert it to true on client side. Then if you save it back to database it will get converted to 1 in database so next time when you read from database it will be read as false on client side. This is all without making any changes to data.
Yes, I agree.