How Can I Use AddRange In Master Details Table

AHSAN ALI 81 Reputation points
2023-12-05T21:21:42.09+00:00

i have 2 table

Order

OrderLineItems

namespace BasketWebApp.Models
{
    using System;
    using System.Collections.Generic;
    
    public partial class Order
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Order()
        {
            this.OrderLineItems = new HashSet<OrderLineItem>();
            this.OrderLogs = new HashSet<OrderLog>();
        }
    
        public int ID { get; set; }
        public string OrderNumber { get; set; }
        public string Account { get; set; }
    
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<OrderLineItem> OrderLineItems { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<OrderLog> OrderLogs { get; set; }
    }
}


namespace BasketWebApp.Models
{
    using System;
    using System.Collections.Generic;
    
    public partial class OrderLineItem
    {
        public int ID { get; set; }
        public Nullable<int> OrderID { get; set; }
        public Nullable<decimal> Price { get; set; }
    
        public virtual Order Order { get; set; }
    }
}

how can i insert 10 records using AddRange i have ListOfOrders with ListOfOrderLineItems

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,596 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,404 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,600 questions
{count} votes