Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

July 20, 2010

SL/RIA/POCO: No Generated Code?

Filed under: ASP.NET RIA Services,C#,Silverlight,VB.NET @ 4:38 pm

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.

22 Comments

  1.   Estela — October 13, 2015 @ 10:38 pm    Reply

    That is very attention-grabbing, You’re an overly skilled blogger.
    I have joined your rss feed and sit up for in search of
    more of your magnificent post. Also, I have shared your web site in my social networks

    Feel free to visit my web site … Star Wars
    T Shirts (Estela)

  2.   Harvey — October 21, 2015 @ 10:58 am    Reply

    Where to buy steroids online shouldn’t be something that that you must look for any longer.

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2021 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs