Click here to Skip to main content
15,034,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I’m implementing a project using asp.net core and I'm new in this field. Employing DB first approach and creating models in Visual studio, in SQl server I have two tables called API and Applicant that have many to many relationship and there is also their junction table called ApiApplicant. Suppose these 3 tables has the following fields each:
Api: ID, name, date, isDeleted.
Applicant:Id,name,type
ApiAppliant:Id,ApiID,ApplicantId,ApiRequestDate,gateId, isDeleted
My ApiApplicant table also has many to one relationship with another table called Gate.
Gate table has the following fields:Id, name.
Now I want to know how can I update ApiApplicant table in my code I appreciate if anyone solve the above problem by showing me a sample relevant linq code.

What I have tried:

 public partial class Apiapplicant
    {
       

        public int Id { get; set; }
        public string ApiRequestDate { get; set; }
        public int? ApiRequestNo { get; set; }
        public int? Apiid { get; set; }
        public int? ApplicantId { get; set; }
        public int? GateId { get; set; }
    
        public bool? IsDeleted { get; set; }
}
        public virtual Api Api { get; set; }
        public virtual Applicant Applicant { get; set; }
        public virtual Gate Gate { get; set; }
Posted
Updated 31-Jan-20 20:55pm

1 solution

var dbContext = new MyEntitiesDbContext();
var theApiapplicant = dbContext.Apiapplicants.Where(a => a.Id == myApiapplicantId).FirstOrDefault();
theApiapplicant.IsDeleted = true;
dbContext.SaveChanges();
Have fun!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900