Blog

All Blog Posts  |  Next Post  |  Previous Post

My Top 10 Aurelius Features - #10 Automapping

Bookmarks: 

Monday, December 5, 2016

This is the #10 feature of My Top 10 Aurelius Features. Follow the link for the full list!

Using the automapping feature is easy: you just need to add the [Automapping] attribute to your class:
type
  [Entity, Automapping]
  TCustomer = class
  private
    FId: Integer;
    FName: string;
  public
    property Id: Integer read FId write FId;
    property Name: string read FName write Name;
  end;

and it will automatically map the class to the database using some conventions. This prevents you from having to manually use the mapping attributes like Column, Table, Id, etc., to tell Aurelius exactly how the database schema will be.

If you already have an existing database, this is not very useful since the convention used by it will probably not match your existing database. But when you do the code-first approach (my favorite) - where you start your application creating the classes, not the tables - this is very handy.

Besides the obvious fact that Automapping speeds up the development process (prototyping is really fast with it), what I really like about Automapping is how it makes you forget about the database and think only about classes: you just don't remember you have a table or a column somewhere in the database - let Aurelius chooses whatever it needs for the underlying database, and focus on your code.

Another interesting thing is that it's not an all-or-nothing feature: you can have use the Automapping attribute but still override it with specific mapping attributes - so you get the best of both worlds: convention with flexibility:
type
  [Entity, Automapping]
  TCustomer = class
  private
    FId: Integer;
    [Column('CUSTOMER_NAME', [TColumnProp.Required], 120)]
    FName: string;
  public
    property Id: Integer read FId write FId;
    property Name: string read FName write Name;
  end;

And to conclude, here is a small video (~4 min) showing Automapping usage:



Wagner Landgraf


Bookmarks: 

This blog post has received 3 comments.


1. Monday, December 12, 2016 at 9:13:15 PM

Excellent post, it would be quite interesting this series of posts in Portuguese, would greatly help those who have difficulty with the English language.

Manoel Pedro Jr


2. Monday, January 9, 2017 at 11:39:32 AM

Manoel, now all videos have Portuguese subtitles. Enjoy! (Todos os vídeos agora tem legendas em português)

Wagner R. Landgraf


3. Thursday, March 23, 2017 at 9:07:23 PM

Obrigado Wagner pela atenção como sempre muito ágil e eficiente.

Napoles




Add a new comment

You will receive a confirmation mail with a link to validate your comment, please use a valid email address.
All fields are required.



All Blog Posts  |  Next Post  |  Previous Post