We have just released a set of slides introducing ORM, SOA, REST, JSON, MVC, MVVM, SOLID, Mocks/Stubs, Domain-Driven Design concepts with Delphi, and showing some sample code using our Open Source mORMot framework. You can follow the public link on Google Drive! This is a great opportunity to […]
Tag - code-first
2014-04-18
Introducing mORMot's architecture and design principles
2014-04-18. Open Source › mORMot Framework
2014-03-13
ORM mapping class fields to external table columns
2014-03-13. Open Source › mORMot Framework
When working with an ORM, you have mainly two possibilites:
- Start from scratch, i.e. write your classes and let the ORM creates all the database structure - it is also named "code-first";
- From an existing database, you define in your model how your classes map the existing database structure - this is "database-first".
We have just finalized ORM external table field mapping in mORMot,
using e.g.
aModel.Props[aExternalClass].ExternalDB.MapField(..)
See
this last commit.
So you can write e.g.
fProperties := TSQLDBSQLite3ConnectionProperties.Create(
SQLITE_MEMORY_DATABASE_NAME,'','','');
VirtualTableExternalRegister(fExternalModel,
TSQLRecordPeopleExt,fProperties,'PeopleExternal');
fExternalModel.Props[TSQLRecordPeopleExt].ExternalDB.
MapField('ID','Key').
MapField('YearOfDeath','YOD');
Then you use your TSQLRecordPeopleExt
table as usual from
Delphi code, with ID and YearOfDeath fields:
- The "internal"
TSQLRecord
class will be stored within the PeopleExternal external table; - The "internal"
TSQLRecord.ID
field will be an external "Key: INTEGER" column; - The "internal"
TSQLRecord.YearOfDeath
field will be an external "YOD: BIGINT" column; - Other internal published properties will be mapped by default with the same name to external column.