I am developing a WebService that excecute linq for sql db and puts the results in a VAR variable. Then I want to serialize the result in VAR format to json using javascript serializer (C #). Something like that:
var sb= from p in ent.people ......... System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(sb.GetType()); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, sb); string json = System.Text.Encoding.Default.GetString(ms.ToArray());
BUT I GOT A RESPONSIBILITY ERROR AS IT:
Type 'System.Data.Objects.ObjectQuery`1[<>f__AnonymousType2d`5[System.String,System.Nu llable`1[System.Int32],System.Nullable`1[System.Int32],System.Int32,System.String]]' cannot be serialized.
Consider labeling it with the DataContractAttribute attribute and mark all of its members that you want to serialize with the DataMemberAttribute attribute. If the type is a collection, consider labeling it with CollectionDataContractAttribute. See the Microsoft.NET Framework documentation for other supported types.
HOW CAN I SEARCH LINQ RESULTS DIRECTLY FOR JSON? Thanks so much for the answers! Enrico
source share