This is a migrated thread and some comments may be shown as answers.

DomainService Questions

1 Answer 56 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paul
Top achievements
Rank 1
Paul asked on 30 Aug 2011, 10:13 AM
Hi, I have a rlinq Domain file and have a domainservice linked to it for RIA services but have a few questions about how to achieve certain things. Say my OpenAccessDomainService.generated.cs file looks like this
namespace CSE.DA.DomainService 
{   
    [EnableClientAccess()]
    public partial class CSENETDomainService : OpenAccessDomainService<CSEEntitiesModel>
    {
        public CSENETDomainService() : base()
        {
        }
        public IQueryable<Am_asset_field> GetAm_asset_fields()
        {
            return this.DataContext.Am_asset_fields;
        }  
                       public void DeleteAm_asset_fields(Am_asset_field am_asset_field)
        {
             
                        // This is a callback method. The actual Delete is performed internally.
                                            WriteDBLog("Delete", User,am_asset_field.Name);
        }
}}
I also have a file called OpenAccessDomainService.cs so I can provide addtional functions to RIA without having to worry about these getting wiped when the other file is regenerated and this also sets up the DB Connection for me.
namespace CSE.DA.DomainService
{
    public partial class CSENETDomainService
    {
    }
 
        protected override CSEEntitiesModel CreateDataContext()
        {
 
            return new CSEEntitiesModel(DBConnection.DBConnectionString, DBConnection.backend, DBConnection.metadataSource);
             
        }
 
     public IQueryable<Am_asset_field> GetAm_asset_fields(int id)
     {
           return this.DataContext.Am_asset_fields.Where(p=> p.Asset_field_id==id);
     }  
 
}

So for my Questions...
1. As you can see from the code I have added a WriteDBLog function within your auto generated callback method. This is not ideal as that class could get overwirtten due to the nature of a auto generated class. So is there a way of overriding the calback methods open access creates so that I can place additional code for delete, insert etc.. action in the OpenAccessDomainService.cs. I know I could just delete the method in the autogenerated class and add it to the other class but is there another way.

2. Also because I'm trying to read a property from the object being deleted I'm getting the error : It is not allowed to read or to write an instance marked for deletion. I know when I used to use the old ObjectScope way you could set property that allowed you to do this but can not seem to find out how you do it when using domain services.

3. When I add a new table in the DB and updated my rlinq file how can I get my domain service to auto create the methods. At the moment I'm editing the OpenAccessDomainService.tt file and adding in the table name, then when I compile the methods get created and that entity will now be available to RIA. Is there a more automated OA way of doing this.

Thanks 

1 Answer, 1 is accepted

Sort by
0
Accepted
PetarP
Telerik team
answered on 02 Sep 2011, 09:35 AM
Hi Paul,

 1. Unfortunately this would be the only way as for now. Please have in mind that if you delete the method from your service you will have to turn off the generation of CUD methods because if you don't do so the next time you generate your service the methods will appear again and that will cause compilation errors.
2. This option is available in our backend configuration. If you open your context you will see that there is a method called GetBackendConfiguration. You will have to modify it in the following way so that you can get the option to work:

public static BackendConfiguration GetBackendConfiguration()
        {
            BackendConfiguration backend = new BackendConfiguration();
            backend.Backend = "mssql";
            backend.ProviderName = "System.Data.SqlClient";
            backend.Runtime.AllowReadAfterDelete = true;
            return backend;
        }
As you can see I have added the backend.Runtime.AllowReadAfterDelete = true to the method.
3. We have plans to develop a separate DSL that would serve just for creating RIA services however given the considerable amount of development that is bound to this task it has been moved in the future (Post Q1 for sure).

Greetings,
Petar
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's SQL Server Community Awards. We are competing in TWO categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or