G Y

G Y

  • 1.2k
  • 229
  • 43.9k

ASP.NET MVC Crud Operation(delete)

Dec 15 2016 11:43 PM

For example Table B (MessageParticipant) is having a foreign key relation ship with Table A (MessageInfo) then how to remove a record from Table B (MessageParticipant).
 
 protected override SAF.Core.FrameworkResponse Delete()
{
SAF.Core.FrameworkResponse response = new SAF.Core.FrameworkResponse();
int result = 0;
string userid = ApplicationContext.UserContext.UserID;
using (FrameworkEntities entity = new FrameworkEntities(SAF.Core.Entity.ConnectionManager.GetEntityConnection(Constants.ModuleName)))
{
base.Entity.MessageParticipant.Where(u => u.ParticipantId == userid).Where(s => s.FolderId == entity.MessageFolder.Where(m => m.Name == "Trash").FirstOrDefault().Id).FirstOrDefault().IsDeleted = true;
entity.MessageInfo.Attach(base.Entity);
entity.Entry(base.Entity).State = System.Data.Entity.EntityState.Modified;
result = entity.SaveChanges();
}
if (result > 0)
{
response.Status = SAF.Common.Status.Success;
}
return response;
}
 
 

Answers (1)