title: Create DbQuery out of View table
body: <p>I am trying to create a DbQuery of ExtendedStudent, from SQL View which was constructed form 2 diffrent tables (see code SQL below).</p>
  
  <p>I have looked at the following posts:</p>
  
  <p><a href="https://www.learnentityframeworkcore.com/query-types#relationships" rel="nofollow noreferrer">Entity Framework Core Query Types</a> And <a href="https://msdn.microsoft.com/magazine/mt847184" rel="nofollow noreferrer">EF Core 2.1 Query Types</a>
  Both have used a model with a navigation propery in it, and then succeeded to fetch it from the Fluent Fluent API.
  But When i tried to do so too, i got exception such as "Invalid column name 'PrefixId1'</p>
  
  <p>The models I use are:</p>
  
  <pre><code>public class ExtendedStudent {
  
      public int IdNumber {get; set;}
  
      public string FirstName {get; set;}
  
      public string LastName {get; set;}
  
      public virtual Prefix Prefix {get; set;}
  
      public int Score {get; set;}
  }
  
  public class Prefix {
  
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.None)]
      public string Id {get ;set;}
  
      [required]
      public string Name {get; set;}
  }
  </code></pre>
  
  <p>The applicationDbContext.cs file is:</p>
  
  <pre><code>public class ApplciationDbContext : DbContext{
  
      DbSet&lt;Prefix&gt; Prefixes {get; set;}
  
      DbQuery&lt;ExtendedStudent&gt; ExtendedStudents {get ;set;}
  
      ...
  
      protected override void OnModelCreating(ModelBuilder builder) {
  
          builder.Query&lt;ExtendedStudent&gt;.ToView("ExtendedStudent");
          builder.Query&lt;ExtendedStudent&gt;.HasOne&lt;Prefix&gt;().WithMany();
      }
  }
  </code></pre>
  
  <p>At last, I tried to fetch the data like this.</p>
  
  <pre><code>var students = applciationDbContext.ExtendedStudents.Include(v =&gt; v.Prefix).ToList();
  </code></pre>
  
  <p>I have created the ExtendedStudents view in SQL like this:</p>
  
  <pre><code>
  CREATE VIEW [Organization].[ExtendedStudent] AS
  SELECT [TableA].[Student].[FirstName]
          ,[TableA].[Student].[LastName]
          ,[TableA].[Student].[PrefixId]
          ,[TableA].[Student].[IdNumber]
          ,[Evaluation].[Student].[Score]
  FROM [TableA].[Student] AS [Students]
  INNER JOIN [Evaluation].[Student] ON [Evaluation].[Student].StudentId = [TableA].[Student].[IdNumber]
  
  </code></pre>
  
  <p>I have tried to add a PrefixId property to ExtendedStudent, or add foreign key, But nothing have worked.</p>
  
  <p>I got an error saying </p>
  
  <blockquote>
    <p>"An exception of type 'System.Data.SqlClient.SqlException' occured in Microsoft.EntityFrameworkCore.dll but was not handled in user code: 'Invalid column name 'PrefixId1'.'</p>
  </blockquote>