Does anyone have experience integrating LINQ into SOA architecture. I've spent all night trawling through documents and books regarding this and I've come to the conclusion that I'm going about things incorrectly...
I've got my database and imported my DBML to set up my data context. I've got a bunch of web methods to transport data back and forth from the db to my ASP.NET page at run time (using AJAX).
The page itself holds a fair whack of data displaying it in a manner not dissimilar to a windows app. In order to achieve the most usable application, I thought that serialization and deserialization of data objects built from sections of the page and passing them back through AJAX calls would be the best way to go.
So imagine if you will as a simplified example a contact database - that's not what I've got, but it's an easy example to demonstrate the point. My page displays my user header information and a custom ascx for each of their pieces of contact information. When a piece of contact info is modified, rather than causing a postback, I'm serializing the contact from that object and sending the XML back to a SaveContact webmethod on my web service that deserializes the object, attaches it to the database context, and then submits the changes.
At least, that's what is supposed to happen...
Thus far, I've got my selects, inserts and deletes working just fine. The issue comes when trying to update existing items in the database. After I've deserialized the contact object, I come to attach it to the data context and my application blows up with one of a number of errors depending upon how I try and achieve this. They range from "Cannot insert an entity with a key that is already in use" to "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported."
Can anyone comment on the pattern I'm using and if this is possible, or have I just been too ambitious with my expectations of LINQ for multi-tier applications? What I've read is that this is not possible, but according to Microsoft's MSDN site, this is exactly the type of architecture LINQ was targetted at... which means that I'm missing something.
Does anyone know the correct way to go about this?