Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify which foreign key column to use in views when scaffolding

How can I specify which foreign key column has to be used in the views when scaffolding? Im some cases MVC seems to be smart enough to take the right column from the other table, but atm I am having an issue with one and was wondering if I can somehow tell which value to use when scaffolding.

public class Tafel
{
    public virtual int Id { get; set; }
    public virtual int TafelNummer { get; set; }
    public virtual int AantalPlekken { get; set; }
    public virtual int CoordX { get; set; }
    public virtual int CoordY { get; set; }
}

This is the model that I am having issue's with, it now shows the Id's in a selectbox, but I want it to show TafelNummer instead when scaffolding.

Here is a picture that will maybe explain it better --> http://i.imgur.com/p29S1J4.png

enter image description here

like image 549
Jordy Avatar asked Nov 09 '22 04:11

Jordy


1 Answers

Set the attribute DisplayColumn in your model like this:

using System.ComponentModel.DataAnnotations;

    [DisplayColumn("TafelNummer")]
    public class Tafel

EntityFramework sets the MetaData, it takes f.e. the first string property. With this addition you can change that. You only have to re-scaffold.

like image 50
Kirsten Avatar answered Nov 14 '22 23:11

Kirsten