How to delete model

Hi,
I try delete specified model after model was created from default (because the aurelius entities model for me is unnecessary, i wrote only my custom build service which use aurelius), I tried do this:

Module:=TXDataServerModule.Create('http://s.com:8077,FireDacMSSQLConnection.CreateConnection);
Module.XModel.Get('aureliusmodeltodelete')

but I can't find any method which is responsible for delete.

How can I delete specific model ?

There is no way to destroy a model, but basically there is no need for it. I didn't understand why you want to destroy it?

Ok ... let me explain:
I have service model like below:

obraz

the question is how can I hide parts EntityTypes, EntityContainers and EnumTypes from model when somebody display https://someurl.com/someservice/$model?
I want display only MainService part, because in this service I have methods which internally uses aurelius entities. From security reasons I can't give possibility to get entities directly via Aurelius Entities e.g. https://someurl.com/someservice/user?user_id=1 and I can't give possibility to show entities schema (db schema).
How can I do this?

Hi,

Finally I did this in way below:

function buildModel():TXDataAureliusModel;
var
  Builder: TXDataModelBuilder;
  Model: TXDataAureliusModel;
  Explorer: TMappingExplorer;
begin
  Explorer := TMappingExplorer.DefaultInstance;
  Model := TXDataAureliusModel.Create(Explorer);
  try
    Builder := TXDataModelBuilder.Create(Model);
    try
      Builder.Build;
      with Builder.Model.FindSchema('XData.Default')do
        begin
          EntityTypes.Clear;
          EntityContainers.Clear;
        end;
      Builder.Build;
      Result:=Model;
    finally
      FreeAndNil(Builder);
    end;
  except
    FreeAndNil(Model);
    raise;
  end;
end;

In main program I create Module like below:

  Module:=TXDataServerModule.Create(
    'http://someurl.com:8080/s',
    FireDacMSSQLConnection.CreateConnection,
    buildModel
  );

In finalization part I free object type TXDataAureliusModel returned from buildModel function:

if Assigned(Module.XModel)then
    begin
      FreeAndNil(Module.XModel);
      Logger.Debug('Model destroyed');
    end;

I hope that it is right way. What do you think about this?

That's a correct approach, yes. But there is a simpler one, which is simply use the Model attribute to use multi-model design and tag the service operations you want to be present in your model.

Then create your XData module passing the model you want to be published:

 Module:=TXDataServerModule.Create(
    'http://someurl.com:8080/s',
    FireDacMSSQLConnection.CreateConnection,
    TAureliusXDataModel.Get('my_model')
  );

Ok ... thanks for the answer ... :grinning:

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.