BlogAll Blog Posts | Next Post | Previous Post
Monday, December 05, 2016This 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 R. Landgraf
This blog post has received 3 comments.
All Blog Posts | Next Post | Previous Post