Deleting objects from the Security database
The following code snippet illustrates how you can delete a particular role using its ID:
using (var context = new CustomDBContext())
{
var result = from r in context.Roles where r.RoleID == 2 select r;
if (result.Count() > 0)
{
Role role = result.First();
context.Roles.Remove(role);
context.SaveChanges();
}
} To delete bulk records, you can use a foreach loop as shown in the following code snippet:
using (var context = new CustomDBContext())
{
var result = from r in context.Roles where r.RoleID == 2 select r;
if (result.Count() > 0)
{
foreach(Role role in result)
{
context.Roles.Remove(role);
}
context.SaveChanges...