Bonjour,
Je d�bute avec ASP NET CORE MVC, j'ai choisi l'approche code first pour mon projet.
D�s lors que je fais une migration puis un update de la base, le nom de mes tables correspond aux noms de mes classes, cependant, j'aurais souhait� que mon mod�le Client corresponde � une table "Clients", j'ai essay� d'utiliser les annotations, de modifier ma m�thode "OnModelCreating" mais rien y fait..
Ci-dessous la m�thode OnModelCreating de mon contexte:
Ma classe Client
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 protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Client>().ToTable("Clients"); modelBuilder.Entity<User>().ToTable("Users"); modelBuilder.Entity<Employee>().ToTable("Employees"); modelBuilder.Entity<Role>().ToTable("Roles"); modelBuilder.Entity<Person>().ToTable("Persons"); foreach (var entity in modelBuilder.Model.GetEntityTypes()) { if (entity.BaseType == null) { entity.SetTableName(entity.DisplayName()); } } }
Pouvez vous m'aider ? Merci d'avance
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 using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Threading.Tasks; namespace Madera.Models { [Table("Clients")] public class Client //: Person { [Key] public int ClientNumber { get; set; } [Required] public Person Person { get; set; } } }







R�pondre avec citation




Partager