c# - Deleting Entity Object with 1 to Many Association to View-Based Entity -


i have model-first entity model contains customer table linked view fetches customer details separate database. relationship 1 many between customer table , view , have navigation property on both customer entity , view entity.

when try perform delete using context.customers.deleteobject(cust) , call context.savechanges() error:

unable update entityset 'viewentity' because has definingquery , no [deletefunction] element exists element support current operation.


i have tried setting on delete cascade , none , both generate same error.

edit: there's not code show, here go:

customer selectedcust = (customer)dgvcustomers.selectedrows[0].databounditem; if (selectedcust != null) {     if (messagebox.show(string.format("are sure want delete customer {0}?", selectedcust.customerid.tostring()),                              "customer delete confirmation", messageboxbuttons.yesno) == dialogresult.yes)     {         // todo - fix         this.reportscheddbcontext.customers.deleteobject(selectedcust);         this.reportscheddbcontext.savechanges();                           } } 

many related posts in agree @overmachine... missing primary key on entity/table.

see..

because has definingquery , no <insertfunction> element exists in <modificationfunctionmapping> element

and

unable update entityset - because has definingquery , no <updatefunction> element exist


edit

just saw comment regarding customer table having primary key view not. not sure whats going on without more of code, need customer object primary key(s) set on it, can use following code delete detached entity object.

this.reportscheddbcontext.entry(selectedcust).state = entitystate.deleted; this.reportscheddbcontext.savechanges();   

if casting type , causing problems, do:

var cust = new customer { customerid = selectedcust.customerid }; this.reportscheddbcontext.entry(cust).state = entitystate.deleted; this.reportscheddbcontext.savechanges();   

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -