I am trying to delete an entity which is added to the context without saving the changes. I am getting FK constraint errors. The entity is temporary which need not to be saved to the database.
This is how I am adding the entity
var productSalesRight = new ProductSupplierSalesRight
{
Product = product,
ProductId = product.ProductId,
SalesRightTypeId = countries.FirstOrDefault().SalesRightTypeId,
SalesRightType = countries.FirstOrDefault().SalesRightType,
Countries = ct
};
product.ProductSupplierSalesRights.Add(productSalesRight);
This is what I am doing in my code to delete
_context.Entry(productSalesRight).State = EntityState.Deleted;
product.ProductSupplierSalesRights.Remove(productSalesRight)
Is there a right way of deleting an entity?