Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe that it does work as described in the tutorial - I just went through that tutorial right now and got the expected result (it did scaffold a "Category" column and drop-down list). </p> <p>My best guess about why it didn't work in your case is that perhaps you missed the <code>CategoryID</code> property from the <code>Product</code> class, or maybe you called it something else. For scaffolding to detect the FK relationship, it's necessary for your entity to have both a "navigation" property (in this case, <code>Category</code>, of type <code>Category</code>) and a "foreign key" property (in this case <code>CategoryID</code> of type <code>int</code>) - without those it won't infer the relationship and hence you wouldn't get the dropdown.</p> <p>In case it helps, here's the full code for the model classes that you can copy and paste into your project:</p> <pre><code>public class Product { public int ID { get; set; } public string Name { get; set; } public int CategoryID { get; set; } public decimal? UnitPrice { get; set; } public int UnitsInStock { get; set; } public virtual Category Category { get; set; } } public class Category { public int CategoryID { get; set; } public string Name { get; set; } public virtual ICollection&lt;Product&gt; Products { get; set; } } public class StoreContext : DbContext { public DbSet&lt;Product&gt; Products { get; set; } public DbSet&lt;Category&gt; Categories { get; set; } } </code></pre> <p>Remember to compile your code before using the "Add Controller" window, otherwise it will not realise that you've changed the code.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload