0

I searched for a good answer for 2 days and I still did not find an easy step-by-step answer to this question.

As you can see, the point is that I need to have a connection between 'boeking' and 'aspnetuser'. 1 aspnetuser can have multiple 'boeking'.

This is the screenshot of mssql: enter image description here

What should I write, in what place to have this connection? Thank you sincerely for taking the time and effort to help me.

This is my boeking class:

public partial class Boeking
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Boeking()
    {
        this.HotelBoekings = new HashSet<HotelBoeking>();
        this.Tickets = new HashSet<Ticket>();
    }

    public string NetUserId { get; set; }
    public int BoekingID { get; set; }
    public int TrajectID { get; set; }
    public System.DateTime DatumBoeking { get; set; }
    public System.DateTime VertrekDatum { get; set; }
    public int ReservatieNr { get; set; }

    public virtual Traject Traject { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<HotelBoeking> HotelBoekings { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Ticket> Tickets { get; set; }
}
pieter-jan
  • 11
  • 4
  • Have you using Code First or Database First? If it uses Code First, you can use a navigation property to `AspNetUsers` table: `public virtual ApplicationUser User { get; set; }` and set `ForeignKeyAttribute` on user ID foreign key property e.g.: `[ForeignKey("User")] public string UserId { get; set; }`. – Tetsuya Yamamoto Apr 07 '17 at 08:36
  • I have the problem that when I insert these 2 lines in my boeing-class, that is doesn't recognize ApplicationUser. Do you know what reference I should use? – pieter-jan Apr 07 '17 at 09:03
  • Which lines and what error you get? Seems I doing mistakes due to lack of detailed info, probably it should be this: `[ForeignKey("UserId")]` public int UserId { get; set; }` followed with `public virtual ApplicationUser ApplicationUser { get; set; }` (see http://stackoverflow.com/questions/23119641/how-to-add-a-foreign-key-in-customer-table-createdby-column-for-aspnetuser-tab as similar issue). – Tetsuya Yamamoto Apr 07 '17 at 09:26

0 Answers0