Bonjour,
J'ai l'entité suivante :qui réfèrent
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 public class AttachmentFile : BaseModels { [Required] public Guid RelayId { get; set; } [Required, StringLength(50), Display(Name = "Nom du fichier", Description = "Nom du fichier avec extention")] public string FileName { get; set; } [Display(Name = "Type de fichier")] public DocumentType Type { get; set; } [NotMapped, Display(Name = "Type de justificatif")] public string TypeAsString { get { return Type.ToDescString(); } } #region Navigation properties [Display(Name = "Voisin Relais")] public virtual Person Relay { get; set; } #endregion }BaseModels contient une Prop Id (Guid).
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53 public class Person : BaseModels { public enum Civilities { M = 1, Mme, Mlle } [ForeignKey("User")] public string UserId { get; set; } [Required, Display(Name = "Nom"), StringLength(50)] public string Lastname { get; set; } [Required, Display(Name = "Prénom"), StringLength(50)] public string Firstname { get; set; } [NotMapped, Display(Name = "Nom complet")] public string Fullname { get { var myTI = new System.Globalization.CultureInfo("fr-FR", false).TextInfo; return string.Format("{0} {1}", Lastname.ToUpper(), myTI.ToTitleCase(Firstname)); } } [Required, Display(Name = "Civilités")] public Civilities Civility { get; set; } [Display(Name = "Voisin relais actif")] public bool IsActivRelay { get; set; } [Display(Name = "Votre photographie")] public string PhotoPath { get; set; } #region Navigation properties public virtual ApplicationUser User { get; set; } [Display(Name = "Adresses")] public virtual ICollection<Address> Addresses { get; set; } [Display(Name = "Téléphones")] public virtual ICollection<PhoneNumber> Phones { get; set; } [Display(Name = "Justificatifs")] public virtual ICollection<AttachmentFile> Supportings { get; set; } public virtual ICollection<CustomerRelay> Customers { get; set; } public virtual ICollection<CustomerRelay> Relays { get; set; } public virtual ICollection<AttachmentFile> Files { get; set; } public virtual ICollection<Availability> Availabilities { get; set; } #endregion }
J'ai ajoutédans mon DbContext (on create...)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 modelBuilder.Entity<AttachmentFile>() .HasRequired(f => f.Relay) .WithMany(p => p.Files);
et j'obtiens ça :sans le fluentAPI, ça me fait un Person_Id1 en plus
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 CreateTable( "dbo.AttachmentFile", c => new { Id = c.Guid(nullable: false, identity: true), RelayId = c.Guid(nullable: false), FileName = c.String(nullable: false, maxLength: 50), Type = c.Int(nullable: false), Person_Id = c.Guid(), }) .PrimaryKey(t => t.Id) .ForeignKey("dbo.Person", t => t.RelayId, cascadeDelete: true) .ForeignKey("dbo.Person", t => t.Person_Id) .Index(t => t.RelayId) .Index(t => t.Person_Id);
please Help
Partager