I am new to LINQtoSQL. I decided to study it because I did not have much experience writing stored procedures in SQL and I thought LINQtoSQL could be an alternative way to access data. Anyway, I created a simple ASP.NET application with a few simple web forms that collect some data from the user.
Then I added the LINQtoSQL Data object (dbml file) to my project. I connected it to a DataSource in my SQL database and allowed OR / Designer to do this "in a magical way to create an entity for me." Everything seemed too good to be true. Until I saved the data that I collected in my web forms back to the database. It was here that I began to learn about serialization issues with LINQtoSQL.
The peculiarity is that my web forms collect data in several stages. Like any ASP developer, I store this data in the ViewState when I view the LifeCycles page. Finally, once my ViewState has all the necessary data, click the submit button to send it to the database using the LINQtoSQL object object. And here I start to get a serialization exception:
System.Runtime.Serialization.SerializationException: Type 'System.Data.Linq.ChangeTracker + StandardChangeTracker' in Assembly 'System.Data.Linq, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089' is not marked as serialized.
I looked on the Internet. I know that my only LINQtoSQL object (which I assign from my ViewState) is seiralizable since it is decorated with the required DataContract and DataMember attributes. After long readings, I tried the solution given by Brain Orrell at the following link, which requires the provision of your own serializer. This seems very complicated for what I'm trying to achieve (just writing a piece of data to a database), and the serialization exceptions still haven't disappeared. Although, oddly enough, my entity is correctly written to the database:
http://borrell.parivedasolutions.com/2008/02/linq-to-sql-updating-in-aspnet-right.html
My question is: what is the correct and easy way to pass ViewState data to a LINQtoSQL object so that it can be written to the database. And if someone knows a specific but good example, I will be grateful for that. Otherwise, I can publish the code from my own project, and we can go from there.
Thanks if in advance.
Fick
source share