I am new to Silverlight RIA services and I have a basic working prototype that utilizes the RIA services with the EntityFramework. Now that I have moved on to the actual project, I am wondering how to utlize non-EntityFramework objects but still use RIA Controls such as the System.Windows.Controls.DomainServices.DomainDataSource so that I can paginate, etc. For example, in my working prototype, I have:
[EnableClientAccess()]
public class RequestService : LinqToEntitiesDomainService<MyEntities>
{
public IQueryable<RequestData> GetRequests()
{
... LINQ query removed ...
}
}
When I change IQueryable<RequestData> to IQueryable<MyRequestData> where MyRequestData is a custom public class I created (and convert the Entity data to ) and then rebuild the application, the client Silverlight application no longer sees the query (build errors).
So my question is, how can I leverage these custom objects in a similar fashion to the EntityFramework objects so that I can still apply pagination, etc?
You can create a POCO class and assign the Key attribute to one of its properties like this…
Then you can create a DomainService class that contains a way to get at the POCO class like this…
This method returns a list of MyClass with a single element in it. But you could return almost anything.
Then on the client side you can invoke the Domain Service like this…
In the event callback, you can cast the sender argument to a LoadOperation and get the data you wanted…
The trick comes from using the ‘Key’ attribute. That makes the whole thing work.