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.

Value conversion on view only works in memory/locally

See original GitHub issue

File 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
smitpatelcommented, Apr 22, 2021

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.

0reactions
mrlifecommented, Apr 22, 2021

Yes, I agree.

Read more comments on GitHub >

github_iconTop 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 >

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