How do I use LINQ-to-Entities to insert data into a specific table?

前端 未结 4 1605
自闭症患者
自闭症患者 2020-12-11 21:28

Question: what is the LINQ-to-Entity code to insert an order for a specific customer?

\"enter

4条回答
  •  情深已故
    2020-12-11 22:01

    I don't get what the problem is, exactly.

    var mycustomer = context.Customers.Where(x => x.id == 100).FirstOrDefault();
    if(mycustomer != null)
    {
      mycustomer.Orders.Add(myorder); 
    }
    context.SaveChanges();
    

提交回复
热议问题