I am doing a simple query with a .Select() on a database view and was expecting to see a shorter list of columns in the generated SQL:
DbContext.LeadSearch.Select(ls => new
{
ls.Id,
ls.BrokerName,
ls.UpdateDate
}).Take(2).ToList();
The generated SQL included all of the columns though:
SELECT TOP(@__p_0) [ls].[Id], [ls].[AssetNumber], [ls].[BrokerId],
[ls].[BrokerName], [ls].[FirstName], [ls].[IsApproved],
[ls].[LastName], [ls].[PurchaseAmount], [ls].[Yadda], [ls].[Yadda2],
... [ls].[UpdateDate] FROM [dp].[vwLeadSearch] AS [ls]
From what I have read elsewhere I was expecting the SQL to have just the "Selected" columns.
LeadSearch is defined as a DbSet:
public DbSet<LeadSearch> LeadSearch { get; set; }
Mapped to the view:
modelBuilder.Entity<LeadSearch>().ToTable("vwLeadSearch").HasKey("Id");
This is with EF Core 2.1.1.
LeadSearchis aDbSetand the entity class is mapped properly, yes.DbSets. When you say database view, how it is mapped in EF Core -DbSetorDbQuerywithToView?