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.

is HasComputedColumnSql bug or wrong way to use?

See original GitHub issue

Include your code

public class User:
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }

       // not want   store  this Column , but   need it    for  search  or  linq  Select Opt
        [NotMapped]
        public string FullName { get; set; }

    }
// false:   the value is computed when the value is read, and does not occupy any actual storage
  modelBuilder.Entity<User>().Property(t => t.FullName).HasComputedColumnSql("[LastName] + ' / ' + [FirstName]",false);

// want  wirte like this  
_userRepository.Where(t => t.FullName .Contains("CC")).First()

_userRepository.Select(t => t.FullName).First()

Include verbose output

Microsoft.Data.SqlClient.SqlException (0x80131904): 列名 'FullName' 无效。

Include provider and version information

EF Core version: Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer) Target framework: (e.g. .NET 6.0) Operating system: IDE: (e.g. Visual Studio 2022)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:24 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
bricelamcommented, Apr 15, 2022

[NotMapped] tells EF that the column doesn’t exist in the database, but it sounds like you do want it to exist in the database as a computed column.

1reaction
rojicommented, Mar 20, 2023

@michiproep I’d be very wary of going down that route; doing this properly - without introducing subtle bugs - is probably going to be difficult and require good knowledge of the query pipeline (and may also involve access to internal APIs which change across releases). I’d advise on finding another way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core (< 5.0) HasComputedColumnSql - computed on ...
Good question. It's unclear from EF Core documentation what type of computed column does HasComputedColumnSql represent. Probably because it's a ...
Read more >
The Fluent API HasComputedColumnSql Method
The Entity Framework Core Fluent API HasComputedColumnSql method is used to specify that the property should map to a computed column.
Read more >
Re: Calculate a Property Value Based on ...
Define simple computed properties (e.g. Concat(LastName, ' ', FirstName)) as computed properties with HasComputedColumnSql; Use EFCore.
Read more >
Foreign Key Relation Not Creating [DropDown ...
Hi There, I have two tables as below. As we see, there is a Foreign Key Relationship with Field, DATAMASTER_DB_ID... When I generate...
Read more >
8 Configuring advanced features and handling concurrency ...
I cover how to configure just one property/column or a whole entity/table to catch concurrency conflicts and how to capture and then write...
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