using (var entity = new USERRIGHTEntities())
{
int tCode = Convert.ToInt32(tPropertiesCode);
//var catetory = entity.T_ModelProperties.Where(o => o.F_ProperieCode == int.Parse(tPropertiesCode));
var catetory = entity.T_ModelProperties.Where(o => o.F_ProperieCode == tCode);
if (catetory.Any())
{
foreach (var item in catetory)
{
entity.DeleteObject(item);
//entity.SaveChanges();
}
entity.SaveChanges();
}
}
可以把entity.SaveChanges();放到循环外边,就可以成功删除了,也可以成功删除多条数据。