Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

One vessel to many photos but ef core 3.1.7 and asp.net 3.1

$
0
0

I have a set of many vessels to which can be set to multiple photos for example lets say the following code I am using asp.net core 3.1 and ef core 3.1.7

   public  class FileAttachments {
    public int Id { get; set; }
     public string Title { get; set; }
     public string File { set; get; }
}

And I have the following for my vessels

public class Vessels : IValidatableObject {
        public int Id { get; set; }
        [StringLength(400)]
        public string Name { get; set; }
    public ICollection<FileAttachments> PhotosAttachments { get; set; }
}

In My Model context I have

       protected override void OnModelCreating(ModelBuilder modelBuilder) {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<Vessels>()
                .HasMany(p => p.PhotosAttachments);
}

But for some reason when I look at my sql i see the following

 You will see their are two columns One VesselId which is being populated correctly and another one [VesselsId] it was only populated after I edited the row and placed 4138 their myself does it work. Can someone tell me why its leaving VesselsId to be null all the time cause when it is null when I added a new photo the record wont appear on my screen at all until i fill it in manually in the db 4138F

For example you will see here that its it null for the third new entry


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>