I have a WCF data service with an entity named Contract.
between Contracts and Quotes, there are many, many: (*) Contract <----> (*) Quotes
I have a method that adds / removes links between contracts and quotes.
and sometimes I get an updateException because I try to add a link between Contract and Quote when the link already exists.
I want to write a query that adds a link only if the link does not exist yet, without having to query the database for existing links between my contract and quotation marks.
Is there a way to do this using expression trees? or linq?
At the moment I am doing this:
void ModifyContract(Contract ctr) { var contractInDb = (from c in service.Contracts.Expand("Quotes") where c.Id == ctr.Id).Single(); foreach(q in ctr.Quotes) { if( ! contractInDb.Quotes.Contains(q)) { service.AddLink(ctr,"Quotes", q); } } service.SaveChanges(); }
source share