Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

July 20, 2010

SL/RIA/POCO: Generated Code

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

This post provides a high-level description of what happens when you compile a Silverlight application that uses WCF RIA Services and plain old CLR objects (POCOs) and the resulting generated code. (See this prior post for a code example.)

After you define your Silverlight project, enable WCF RIA Services, and add your Domain Service class with appropriate method(s), you have enough to build your solution and view the generated code.

In Solution Explorer, select your Silverlight project and click the Show All  Files button in the toolbar. You will then see a Generated_Code folder containing a *.g.cs file. This contains the code generated by Visual Studio and defines the classes detailed below.

Entity class

This class is generated from information in the business layer (your POCO classes on the server) and includes all of the class’s properties. It inherits from the DomainServices Entity class (not to be confused with the Entity Framework (EF) Entity class).

The compiler looks at the properties of the class and any attributes on those properties. It then generates a copy of those properties with their associated attributes in the generated code file.

How does it know which business layer class to use for the Entity class? It determines the appropriate class based on the parameters and/or return values on the methods in your Domain Service class.

If you have a query style method, it returns either a single entity or an IEnumerable or IQueryable of the entity. The compiler uses that information to determine which business layer class to use.

If you have an insert, update, or delete method, the parameter defines the entity. The compiler uses that information to determine which business layer class to use.

The compiler attributes the generated class as a DataContract and each property as a DataMember so it can be processed appropriate when the class is used as part of a WCF service. (WCF RIA Services uses WCF "under the covers".)

Domain Context class

This class is generated from information in the Domain Service class that you created. It inherits from DomainContext.

The compiler defines a WCF service contract in this class. It also defines wrapper methods for the methods in your Domain Service class.

When your Silverlight application calls methods in this class, the class makes the WCF service calls to the Domain Service class in the ASP.NET project.

Here it is in picture form:

image

Enjoy!

1 Comment

  1.   srinivas — September 21, 2010 @ 5:03 pm    Reply

    Can you please explain in detail how compiler will work for add, update and delete.

RSS feed for comments on this post. TrackBack URI

Leave a comment

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