SL/RIA/POCO: No Generated Code?

Posted Tue, Jul 20 2010 14:38 by Deborah Kurata

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.

Enjoy!

EDITED 8/12/10: Incorporated Colin Blair's comment from 8/11/10.

Comments

# re: SL/RIA/POCO: No Generated Code?

Wednesday, August 11, 2010 3:29 PM by Colin Blair

The DomainService does not need to be defined within the ASP.NET project, it just needs to be referenced by the ASP.NET project.

# re: SL/RIA/POCO: No Generated Code?

Thursday, August 12, 2010 10:30 AM by Deborah Kurata

Hi Colin -

Thanks for the clarification. I will update the post accordingly.

Thanks also for your help on the forums!

# re: SL/RIA/POCO: No Generated Code?

Friday, October 01, 2010 9:16 AM by oski

I had only one method in DomainService and it was not public

--> no sight of my poco was in generated code

until I understood to mark thet method as public

this caused also that there was no datasource available for XAML designer (until correction)

***

bad english sorry

# re: SL/RIA/POCO: No Generated Code?

Saturday, October 16, 2010 3:07 PM by idefix

I have a problem on the client side generated code. The navigation properties are not generated ! any ideas ?

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: