mES MODELS SONT/
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
-------------------------
 public class book    {    
       public int id { get; set; }
        public string name { get; set; }
        public int nbr_total { get; set; }
        public int nbr_disponible { get; set; }
 
        public virtual ICollection<commande> comandes { get; set; }
    }
------------------------
public class personne
    {
        public int id { get; set; }
        public string name { get; set; }
        public virtual ICollection<commande> comandes { get; set; }
    }
--------------------
public class commande
    {
        public int id { get; set; }
        public int perssonneid { get; set; }
        public int bookid { get; set; }
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
        [Display(Name = "Start Date")]
        public DateTime StartDate { get; set; }
 
        public virtual book bookgetr { get; set; }
        public virtual personne personngeter { get; set; }
    }
___________________________________________________________
 public class biblioContex:DbContext
    {
        public DbSet<book> boks { get; set; }
        public DbSet<personne> presons { get; set; }
        public DbSet<commande> commands { get; set; }
    }
mais dens l'affichage de list de command je veux aficher le nom de book et le nom de la personne
vs généré automatiquement le nom de book sont le nome de la personne

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
  public ActionResult Index()
        {
            var commands = db.commands.Include(c => c.bookgetr);
            return View(commands);
        }
 
memesi j'ai utiliser selemmnet persnnegetr je reçois pas le nom de la perssonne 
var commands = db.commands.Include(c => c.personngter);
            return View(commands);
pour mon cas je dois incuder les deux champs mais il fonction pas
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
public ActionResult Index()
        {
            var commands = db.commands.Include(c => c.bookgetr).Include(c => c.personngeter);
            return View(commands);
        }
dans le page html

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 
@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.bookgetr.name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.personngeter.name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.StartDate)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.id }) |
            @Html.ActionLink("Details", "Details", new { id=item.id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.id })
        </td>
    </tr>
}