469,925 Members | 1,435 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,925 developers. It's quick & easy.

Updating data using LINQ to SQL and Web Services

balabaster
797 Expert 512MB
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?
Oct 15 '08 #1
1 1513
kenobewan
4,871 Expert 4TB
Came across this article, not sure if it is helpful:
Linq up that Webservice
Oct 18 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by willow1480 | last post: by
14 posts views Thread by el_sid | last post: by
3 posts views Thread by Shawn Ramirez | last post: by
13 posts views Thread by G | last post: by
7 posts views Thread by =?Utf-8?B?Q2hha3JhdmFydGh5?= | last post: by
15 posts views Thread by EDBrian | last post: by
13 posts views Thread by Matthias S. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.