Ho un modello entità Model-First che contiene una tabella Customer collegata a una vista che recupera i dettagli del cliente da un database separato. La relazione è da uno a molti tra la tabella Cliente e la Vista e ho una proprietà di navigazione sia sull'entità Cliente che sull'entità Visualizza.Eliminazione di oggetto Entity con associazione da 1 a molti a entità View-
Quando si tenta di eseguire un eliminare utilizzando context.Customers.DeleteObject (cust) e chiamare context.SaveChanges() ottengo un errore:
Unable to update the EntitySet 'ViewEntity' because it has a DefiningQuery and no [DeleteFunction] element exists element to support the current operation.
Ho provato a fissare On Delete Cascade e Nessuno ed entrambi generano lo stesso errore.
EDIT: Non c'è molto codice per mostrare, ma qui si va:
Customer selectedCust = (Customer)dgvCustomers.SelectedRows[0].DataBoundItem;
if (selectedCust != null)
{
if (MessageBox.Show(String.Format("Are you sure you want to delete Customer {0}?", selectedCust.CustomerID.ToString()),
"Customer Delete Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// TODO - Fix this
this.ReportSchedDBContext.Customers.DeleteObject(selectedCust);
this.ReportSchedDBContext.SaveChanges();
}
}
mostraci il codice bro –
Il tuo Entità e il tuo tavolo hanno una chiave primaria? – Overmachine
L'entità basata su una tabella reale (Cliente), l'entità basata sulla vista non lo fa poiché si basa su una vista. – Overhed