[英]Delete in cascade
我是asp.net和mvc的新手。 我上了一課AsyApp
public class AsyApp
{
[Key]
public int AsyAppId { get; set; }
[DisplayName("Nom")]
public string Name { get; set; }
public virtual ICollection<Scene> Scenes { get; set; }
}
它有一個場景集合
public class Scene
{
[Key]
[Required]
public int SceneId { get; set; }
[ForeignKey("AsyApp")]
public int AsyAppId { get; set; }
[Required]
public virtual AsyApp AsyApp { get; set; }
[ForeignKey("Name")]
public int NameId { get; set; }
[DisplayName("Nom")]
public virtual Translation Name { get; set; }
public int Order { get; set; }
}
並且Scene具有來自類Translation的屬性Name
public class Translation
{
[Key]
[Required]
public int TranslationId { get; set; }
public string Fr { get; set; }
public string En { get; set; }
}
這是我的問題。 我將使用Translation類來處理應用程序中每個字符串的語言。 我可能在任何其他班上
我希望在刪除應用程序時刪除適當的場景和本地化
這是我刪除應用程序的代碼
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
AsyApp asyApp = db.AsyApps.Find(id);
if (asyApp == null)
{
return HttpNotFound();
}
db.AsyApps.Remove(asyApp);
db.SaveChanges();
return RedirectToAction("Index");
}
場景接縫將自動刪除,但不會自動刪除與它們關聯的本地化...
希望你能幫我
非常感謝
查看此鏈接: https : //msdn.microsoft.com/zh-cn/data/jj591620.aspx#CascadeDelete
您可以使用Fluent API啟用級聯刪除。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.