SL/RIA/POCO: No Generated Code?
Tue, Jul 20 2010 14:38
This prior post described the code that is generated when you compile a Silverlight application that uses WCF RIA Services and your own plain old CLR objects (POCOs). This post provides some ideas if something goes horribly wrong and the compiler does not generate the appropriate code.
If you build your solution and you don't get the generated code described in this prior post, here are some things to check:
- In your business layer component (where your business classes are defined):
- The class(es) you want to access from Silverlight must be a public.
- The properties that you want to access from Silverlight must be public.
- The Key attribute must be defined on one of the business class public properties.
- In your Silverlight project:
- Ensure you have a WCF RIA Services link.
- Open the Silverlight project properties. The WCF RIA Services link is defined at the bottom of the properties dialog
- In your ASP.NET project (that was created automatically when you created your Silverlight project)
- You must have a reference defined to your business layer component.
- In your Domain Service class:
- The Domain Service class must be defined within the ASP.NET project (or in a class referenced by the ASP.NET project).
- It must have the EnableClientAccess attribute on the class.
- It must inherit from the DomainService class (or one of its specialized classes such as LinqToEntiesDomainService if you are using Entity Framework)
- If you define a Query method to retrieve data from your business class, the Query method:
- Must be a method and not a property.
- Must return one of the following:
- A single entity (instance of the business object class)
- An IEnumerable<T> where T is the entity
- An IQueryable<T> where T is the entity
- Can have any parameters.
- Can have any name.
- Can (but does not have to) have a Query attribute to define the method as a query.
- If you define an Update method to update data from your business class, the Update method:
- Must be a method.
- Must have no return value.
- Must pass the entity as a parameter.
- Must either:
- Start with "Update", "Change" or "Modify
- Or have an Update attribute
The first time I tried using WCF RIA services, I did not know about the Key attribute, so did not get any generated code.
More recently, I used a converter to convert some working C# code from my Domain Service class into VB and then could not get any generated code from the VB solution. I did not immediately notice that the converter translated IEnumerable<Customer> to just IEnumerable (non-generic). So the compiler did not know which entity to process.
I hope the above checklist will help you quickly find why you are not getting generated code. If you have other things to add to this checklist, I'd love to hear from you. Please add a comment to this post.
EDITED 8/12/10: Incorporated Colin Blair's comment from 8/11/10.