Witam. Piszę apke w winforms i korzystam z entity framework. Mam problem z kaskadowym usuwanie rekordów. Jak to wyłączyć. korzystam z tego tutoriala: http://www.entityframeworktutorial.net/code-first/cascade-delete-in-code-first.aspx
ale to nie pomaga:
Moje klasy to:
public class Category
{
public Category()
{
this.Products = new HashSet<Product>();
}
[Key]
public int Id { get; set; }
[Required(ErrorMessage ="Pole wymagane"), MaxLength(16)]
[Unique]
[Display(Name="Nazwa kagegorii:")]
public string Name { get; set; }
[Display(Name = "Opis kategorii:")]
public string Description { get; set; }
public string Image { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
public class Product
{
public Product()
{
this.ProductImage = new HashSet<ProductImage>();
}
public int Id { get; set; }
public string Name { get; set; }
public string EAN { get; set; }
public string Description { get; set; }
public string ShortDescription { get; set; }
public int Price { get; set; }
public bool Active { get; set; }
public string SKU { get; set; }
public int CategoryId { get; set; }
public int TaxId { get; set; }
public virtual Category Category { get; set; }
public virtual Tax Tax { get; set; }
public virtual ICollection<ProductImage> ProductImage { get; set; }
}
robiłem też według tego http://stackoverflow.com/questions/9136255/ef4-1-code-first-how-to-disable-delete-cascade-for-a-relationship-without-navi
ale dalej nic. Chodzi o to, że chce aby przy usuwaniu kategorii jeśli są jakieś produktu to żeby wystąpił jakiś Exception . A jest tak, że jak dam usunięcie kategorii to usuwa mi wszystko czyli produkty należące do usuwanej kategorii.