Skip to content

Model Building

Todd Thomson edited this page Aug 17, 2018 · 10 revisions

Database entity models are built using a fluent API for mapping POCO objects to database tables. Within your DataContext, override the OnModelBuilding() method.

Mapping

Entities.Sqlite provides the following mapping builders to build your entity model. Follow each link to see complete details of each mapping.

By Convention

Entities.Sqlite provides entity auto mapping by conventions for table naming and setting a primary key.

Entity Mapping

For each entity within your data context specify your mapping with the following code.

protected override void OnModelBuilding( RelationalModelBuilder modelBuilder )
{
    modelBuilder.Entity<TodoItem>( entity =>
    {
        // Additional entity mapping goes here
    } );
}

Use .ToTable( string tableName ) to set your table name.

Relationship Mapping

Entities.Sqlite supports 1-1 and 1-many relationships.