is HasComputedColumnSql bug or wrong way to use?
See original GitHub issueInclude 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:
- Created a year ago
- Comments:24 (12 by maintainers)
Top 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 >
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
[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.@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.