passing a list of entities to a wcf ria domain service method

Aug 13, 2011 at 7:12 AM
Edited Aug 13, 2011 at 7:12 AM

Hi.

Thank you for WCF RIA Services Contrib.

I have read a lot of posts from developers wanting to pass an array, list, or collection of objects to a wcf ria domain service method and facing some wcf ria limitations.

Here are just some of those posts:
http://www.codemeit.com/wcf/wcf-ria-service-pass-array-list-or-collection-as-parameter-to-invoke-method.html
http://forums.silverlight.net/p/150008/335340.aspx#334818
http://sklementiev.blogspot.com/2010/03/ria-and-dto.html
http://sklementiev.blogspot.com/2010/04/ria-and-dto-part-2.html
http://forums.silverlight.net/t/183679.aspx

I do not want to implement those work-arounds because they require database schema changes and so I've come here looking for a better solution. :)

Is there any sample code that illustrates how to use DataContractSerializer, Import, and Export in this scenario for both the silverlight client and server?

The collection of entities in this scenario will not always be inserted in the database.

Thank you.

Coordinator
Aug 13, 2011 at 2:35 PM

You should ask that question at the WCF RIA Services forum on Silverlight.net. You are also better off explaining what problem you are trying to solve, not how you are trying to solve it. Your statement that the collection of entities "will not always be inserted in the database" is interesting as that seems to indicate that sometimes your collection of entities WILL be inserted into the database. If entities will be moved into the database then they need to be submitted through the SubmitChanges.

Beyond that though, most of your links are from earlier beta releases of WCF RIA Services. If you are using at least SP1 of WCF RIA Services you can pass a list of entities through an Invoke. It is generally a bad idea, but you can do it.

Nov 1, 2011 at 2:50 PM

Having been trying to solve the same seemingly simple problem, I feel icnocop's pain.  

I think he might have been asking if your tools can help with this problem.  For example, at minimum, I'm guessing your T4 RIA template generator could be used to create service operations that serialize a list on the Silverlight side, send the XML to the server, and then deserialize the list on the server side.

Nov 1, 2011 at 9:56 PM

@Colin, Thank you.  I was able to resolve the issue using the Invoke command as you suggested.

@joshmouch, I was able to resolve this issue by starting from scratch and performing incremental updates to simple functionality until I was able to resolve the issue.

I believe it had to do with not using the WCF RIA SP1 binaries and that caused a lot of confusion and I ended up not having to serialize entities into xml, etc.

After upgrading to WCF RIA SP1, you might want to manually delete your bin and obj folders and do a rebuild just in case you still get compiler and\or linker errors that don't make sense.

Thank you.

Jan 28, 2012 at 10:40 AM
Edited Jan 28, 2012 at 10:44 AM

Unfortunately, the problem has re-appeared for me.  :(

C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Ria.Client.targets(304,5): error : Operation named 'Operation1' does not conform to the required signature. Parameter types must be an entity or complex type, a collection of complex types, or one of the predefined serializable types.

Note that the message does not say "a collection of entities".

I have WCF RIA Service V1.0 SP1 4.1.60114.0 installed on my machine, Windows 7 Ultimate SP1 64-bit, Visual Studio 2010 Premium SP1.

I am not yet sure what the problem is.

[Invoke]
public List<EntityB> Operation1(List<EntityA> MyEntities) {...}

[Query]
public IQueryable<EntityA> GetEntityAs()
{
throw new NotImplementedException();
}

[Query]
public IQueryable<EntityB> GetEntityBs()
{
throw new NotImplementedException();
}

 

[DataContract(IsReference=false)]
public class EntityA
{
[Key]
[DataMember]
public long EntityAId {get; set;}

[DataMember]
public long A {get; set;}
}

[DataContract(IsReference=false)]
public class EntityB
{
[Key]
[DataMember]
public long EntityBId {get; set;}

[DataMember]
public long B {get; set;}
}

Any advice?

Thank you.

Jan 28, 2012 at 6:52 PM

Ok, I just upgraded to WCF RIA Services V1.0 SP2 and WCF RIA Services Toolkit (September 2011) and it is compiling fine now.

I had WCF RIA Services 1.0 SP1 and WCF RIA Services Toolkit (August 2011) previously.