0
데이터베이스에 두 개의 테이블이 있습니다. 하나는 요리법 용이고 다른 하나는 재료 용입니다. 특정 레시피가 삭제되면 모든 성분도 사라지게됩니다. 캐스케이드 속성이 설정된 일대 다 관계를 선언했지만 일부 레시피를 삭제하면 관련 재료가 삭제되지 않습니다.계단식 삭제가 작동하지 않습니다.
여기 내 테이블은 다음과 같습니다이 내 삭제 작업입니다
public class Recipe_Model
{
[PrimaryKey AutoIncrement]
public int RecipeID { get; set; }
public string RecipeName { get; set; }
public double RecipeCost { get; set; }
public double ServingsNo { get; set; }
public double CostPercent { get; set; }
public double SellingPrice { get; set; }
public double CostPerServing { get; set; }
[OneToMany(CascadeOperations = CascadeOperation.All)] // One to many relationship with Ingredients
public ObservableCollection<Ingredients_Model> Ingredients { get; set; }
}
public class Ingredients_Model
{
[PrimaryKey AutoIncrement]
public int IngredientID { get; set; }
[ForeignKey(typeof(Recipe_Model))]
public int RecipeID { get; set; }
public string IngredientName { get; set; }
public string UsedUnit { get; set; }
public string PurchasedUnit { get; set; }
public double QuantityUsed { get; set; }
public double QuantityPurchased { get; set; }
public double PurchasePrice { get; set; }
public double IngredientCost { get; set; }
}
:
public void DeleteRecipe()
{
using (SQLiteConnection database = DependencyService.Get<ISQLite>().GetConnection())
{
var recipe = database.Get<Recipe_Model>(RecipeID);
database.Delete(recipe, true);
}
}
내가 무슨 일을하고 있는가?
현재 메모리에있는 개체를 삭제하는 방법은 무엇입니까? 또한 내가이 권한을 얻는다면, 현재 조작하고있는 객체가 메모리에 저장 될 것입니다. 그렇죠? 이전에이 작업을 수행했습니다. database.Delete (RecipeID); 하지만 작동하지 않았으므로 Get 메서드로 변경하여 테스트 해 보았습니다. 이 쿼리는 먼저 메모리에서 객체를 가져 옵니까? –
Tehreem
아, 그것을 해결했습니다. 그리고 메모리 문제의 모든 개체를 잡았어! 감사. – Tehreem