Computed column in EF Core incorrect mapping

.net entity-framework entity-framework-core

Question

Trying to use a Computed column in my query but it seems EF Core handles it like any other column and just ignores the mapping. Is there somehting i do wrong here? or do i misunderstand the usage of the computed column :S This is almost the same examples as the documentation are using.

EF Core documentation

I am running MapUsers(modelBuilder.Entity<User>()); inside the OnModelCreating.

Mapping:

private static void MapUsers(EntityTypeBuilder<User> entity)
{
    entity.Property(p => p.FullName)
          .HasComputedColumnSql("[FirstName] + ' ' + [LastName]");
    entity.ToTable("User");
}

this is the generated query:

 SELECT [FirstName], [u].[FullName], [u].[LastName]
 FROM [User] AS [u]

Managed to get it to work in the query by using this line instead of using a strongly typed property

$"{u.FirstName} {u.LastName}".Contains(query)
1
1
9/3/2016 10:55:11 AM

Accepted Answer

Had the same confusion and ended up asking the EF team.

The explanation is that the SQL query you put as parameter is only used for migrations. If you're using database-first or not using migrations at all, that parameter is not used.

0
10/12/2016 8:51:51 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow