User View in Aurelius

Hi,

 I wish I could use the VIEWs stored in the db from Aurelius, is it possible?
 How can I do it?

Thank's

You can map an entity to the view the same way you do with a table, just put the name of the view in the [Table] attribute, and Aurelius will perform a SELECT FROM <view_name> statement.

But, of course, that entity will be read-only, you will not be able to execute data modification operations on it.

Ok,

Thank's

But when run the program i received error: 'Member 'FId' not found in class MyView

And what is your view declaration? You MyView class declaration? 


I solved by inserting a fake ID field in the view ...
not beautiful but it works ...


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This is the view

CREATE OR REPLACE VIEW public.riepilogopertipologia(
    id,
    Descr,
    Count)
AS
  SELECT row_number() OVER(
  ORDER BY ta.Descr) AS id,
           ta.Descr,
           count(*) AS Count
  FROM apparati ap
       LEFT JOIN tipiapparati ta ON ta.id = ap.idtipoapparato
  WHERE ap.seattivo = true
  GROUP BY ta.Descr;


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This is the class

  TRiepilogoPerTipologiaVWTableDictionary = class;


  [Entity]
  [Table('RiepilogoPerTipologia')]
  [Description('')]
  [Id('FId', TIdGenerator.IdentityOrSequence)]
  TRiepilogoPerTipologiaVW = class
  private
    [Column('Id', [TColumnProp.Required])]
    [Description('')]
    FId: Int64;

    [Column('Count', [])]
    [Description('')]
    FCount: Int64;

    [Column('Descr', [], 80)]
    [Description('')]
    FDescr: string;

  public
    constructor Create;
    destructor Destroy; override;
    property Id: Int64 read FId; 
    property Descr: string read FDescr;
    property Count: Int64 read FCount;

  end;



  TRiepilogoPerTipologiaVWTableDictionary = class
  private
    //FId: TDictionaryAttribute;
    FCount: TDictionaryAttribute;
    FDescr: TDictionaryAttribute;
  public
    constructor Create;
    //property Id: TDictionaryAttribute read FId;
    property Descr: TDictionaryAttribute read FDescr;
    property Count: TDictionaryAttribute read FCount;

  end;




implementation
  { TRiepilogoPerTipologiaVW }

constructor TRiepilogoPerTipologiaVW.Create;
begin
  inherited;

end;

destructor TRiepilogoPerTipologiaVW.Destroy;
begin
  inherited;
end;


{ TRiepilogoPerTipologiaVWTableDictionary }

constructor TRiepilogoPerTipologiaVWTableDictionary.Create;
begin
  inherited;
  //FId := TDictionaryAttribute.Create('Id');
  FCount := TDictionaryAttribute.Create('Count');
  FDescr := TDictionaryAttribute.Create('Descr');
end;

end.

if Descr is unique, you can simply add it as the ID. Every view should in theory have one or more fields that identifies its rows uniquely. Simply use those fields.

Hi, Wagner
  About that:
  It is already possible to export views with the data modeler?
  And create views with data modeler?

Thanks

Hi, unfortunately no, in this case you have to create the entity class manually from code.

Hi, Wagner,
In case you try to use the "updated database" function you create this error, the entity mapped to the view is recreated as a table ....
how can I prevent this from happening, keeping the convenient updatedabase function?
Thx in advance.

You need to use multimodel design: https://www.tmssoftware.biz/business/aurelius/doc/web/multi-model_design.html.

This allows you to logically separate your entities, this way you can have a model "Database" or "Schema" with only the classes which tables should be created in the database.

Thank's for your help!