I have a simple class:
[DataContract]
public class Book
{
[DataMember]
public Int32 ID { get; set; }
[DataMember]
public Nullable<Int32> AuthorID { get; set; }
}
Which is retrieved via a WCF Service like:
public class BookService : IBookService
{
IService _service;
public BookService()
{
_service = new BookService();
}
public IEnumerable<Book> GetBooks()
{
var Books = _service.GetBooks();
return Books;
}
}
I now want to extend this to include an additional function that would allow a LINQ query to include additional properties on the Book class (not shown in the cut down example above). The function for this (which works when included and called from within an MVC app) is:
public IEnumerable<Book> GetBooks(params Expression<Func<Book, object>>[] includes)
{
var Books = _service.GetBooks(Expression<Func<Book, object>>[]>(includes));
return Books;
}
However, when ran from an WCF Service this generates an error as it can't be serialized:
System.ServiceModel.Description.DataContractSerializerOperationBehavior contract: http://tempuri.org/:IBookService ----> System.Runtime.Serialization.InvalidDataContractException: Type 'System.Linq.Expressions.Expression
1[System.Func
2[Foo.Book,System.Object]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.
I added the DataContract/DataMember attributes to the class so that it could be serialized, however I'm not sure what I need to do to allow the function parameter to be serialized.
Anyone have ideas on what I can do to allow this function to be used in the WCF service?