I am currently working on a project using both the Entity Framework (a version integrated with the .NET Framework version 3.5 SP1) and many AJAX-based functions that I implement using jQuery on the client side and ASP.NET WebMethods on the server side .
I usually create new entities using WebMethod, which takes an object as a parameter as follows:
[WebMethod] public static void Add(User user);
When calling this method, I collect an object similar to the object (in terms of properties) in JavaScript, and pass it as a JSON string. However, when I tried to convey related objects in a many-to-many relationship, I ran into a problem. Suppose a user-defined object has a one-to-many relationship with a Flight object — adding a new user with several (new) flights is problematic. The following approach:
this.user.Flight = []; var x = new Object();
Results from an ASP.NET error (during the deserialization phase), which indicates that the List cannot be converted to an EntityCollection.
Then I tried this approach:
this.user.Flight = {}; var x = new Object();
In this case, WebMethod was called successfully, but the flights were completely lost (calling the user.Flight.Count () function in the returned WebMethod 0).
Does anyone know how I can transfer multiple flights to EntityCollection in WebMethod?
source share