Search code examples
riat4domain-service-class

overriding RIA DomianService code generation


I need to insert a common set of code in Get method of all the entities generated by the RIA Domain Service wizard. Is it possible to override Domain Service wizard's code generation so I can insert that code automatically?

Thanks, Ankur


Solution

  • You can definitely modify and edit (or even write your own) T4 templates that are responsible for the code generation.. something along the lines of these two links:

    T4 Code Generator for WCF RIA Services

    Using T4 to change the way RIA services work

    Furthermore, you can check the T4 template for RIA services (server side) from the WCF RIA Services Contrib project on CodePlex that allows you to modify your GET methods as follows:

    public IQueryable<<#= Entity.Name #>> Get<#= Entity.Name #>()
    {
         //Inject Custom code here
         return this.ObjectContext.<#= Entity.Mapping.StoreEntitySet #>;
    }