Skip to content

[Question] About database initialization #88

@postb99

Description

@postb99

Hi Dmitry,

My app will check at startup if the database exists. I read that I could do that using EF Core in an ExtCore EFCore repository class with this code: "storageContext.Database.EnsureCreated();".

For now I'm still working on making this call work. But I rather call this in a module than in a repository.

I was wondering about adding some method to IStorageContext such as "EnsureDatabaseCreated()" or so. Indeed, ExtCore is ORM-agnostic, so, EF Core is a choice among another choices. In my case, with EF Core, I cast the IStorageContext to EF's StorageContextBase.

How do you handle this question in Platformus? Thanks for the ideas.

Edit
After reading some EF Core tutorials, everything isn't clear to me yet (I'm new to EF :) ):

  • do I need to create my own DbContext as I see in the EF Core tutorials? Doesn't ExtCore EF create it already? In Startup I configure the storage context options but don't register the db context service. [Edit 2: answering to myself: DbContext is available whenever I have a IStorageContext reference].
  • what code calls the RegisterEntities method? For now I set a low priority to my EnsureCreated method call so it gets called before RegisterEntities, I think it is wrong.
  • I read some docs about migration and that you can call this programmatically.

I have the approach of creating the database from the application because I want the extensions to add their own tables (in addition to records).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions