如何设置我的域和LINQ语句,以便从数据库中删除记录?
public class Category {
public int CategoryId { get; set; }
public string Name { get; set; }
public List<Product> Products{ get; set; }
}
public class Product {
public int ProductId { get; set; }
public string Name { get; set; }
public int CategoryId {get; set; }
public Category Category{ get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是删除类别,并能够将删除级联到所有子产品.
这是唯一的方法吗?
Category category = new Category() { CategoryId = 1 } ;
context.AttachTo("Category", category);
context.DeleteObject(category);
context.Savechanges();
Run Code Online (Sandbox Code Playgroud)