title: SQL joins in Entity Framework (WPF MVVM)
body: <p>I want to do a simple join with raw sql using Entity Framework.</p>
  
  <p>My model-classes are defined as follows:</p>
  
  <pre><code>public class Price
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id {get; private set;}
      public int ProductId {get; set;}
      public double Price {get; set;}
      public virtual Product Product {get; set;}
  }
      public class Product
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id {get; private set;}
      public string Name {get; set;}
      public ICollection&lt;Price&gt; Price {get; set;}
  }
  </code></pre>
  
  <p>My PriceContext class as follows:</p>
  
  <pre><code>public class PriceContext : DbContext
  {
  public DbSet&lt;Price&gt; Prices {get; set;}
  public DbSet&lt;Product&gt; Products {get; set;}
  
  public PriceContext() : base("ConnectionString") {}
  
  public List&lt;Price&gt; FindAll()
  {
      string sqlQuery= @"select products.name, prices.[type], prices.[from], prices.price, prices.pricelistname  from products, prices where prices.productid = products.id;
  
      return Prices.SqlQuery(sqlQuery).ToList&lt;Price&gt;();
  }
  }
  </code></pre>
  
  <p>My ViewModel has a method as follows:</p>
  
  <pre><code>public void FindAll()
      {
          var context = new PriceContext();
          var prices = context.FindAll();
          ObservablePrices = new ObservableCollection&lt;Price&gt;(prices);
      }
  </code></pre>
  
  <p>My WPF view runs <code>ViewModel.FindAll()</code> whenever it loads and also has a <code>DataGrid</code> element bound to <code>ObservablePrices</code>.</p>
  
  <p>The query <code>sqlQuery</code>does not seem to work. If I however change it to <code>select * from prices</code> it works fine (just to see that all my bindings etc. are working as intended). I can't seem to query the table <code>products</code> from within this context.</p>