Entity Framework 6 with SQLite 3 Code First - Won't create tables

后端 未结 4 1945
我寻月下人不归
我寻月下人不归 2020-11-27 03:04

Using latest versions of EF6 and SQLite from NuGet. I finally got the app.config file to work after some useful posts on Stackoverflow. Now the problem is that the tables ar

4条回答
  •  Happy的楠姐
    2020-11-27 03:31

    I started with the code from fried and created a project which lets you use CodeFirst. The project is available open source on GitHub or as NuGet Package.

    If you encounter any problems or miss a feature, feel free to open a new issue on GitHub. Of course PRs are very welcome.

    Edit (26.04.2016):

    In the meantime I did a lot in this project.

    The following (default EF) functionality is supported:

    • Tables from classes (supported annotations: Table)
    • Columns from properties (supported annotations: Column, Key, MaxLength, Required, NotMapped, DatabaseGenerated, Index)
    • PrimaryKey constraint (Key annotation, key composites are supported)
    • ForeignKey constraint (1-n relationships, support for 'Cascade on delete')
    • Not Null constraint
    • Auto increment (an int PrimaryKey will automatically be incremented)
    • Index (Decorate columns with the Index attribute. Indices are automatically created for foreign keys by default. To prevent this you can remove the convetion ForeignKeyIndexConvention)

    There are also some features exclusive for SQLite, which are not supported by default:

    • Unique constraint (Decorate columns with the UniqueAttribute, which is part of this library)
    • Collate constraint (Decorate columns with the CollateAttribute, which is part of this library)

    There are two ways to use the functionality of this library.

    1. Make use of the DbInitializers:

      • SqliteCreateDatabaseIfNotExists
      • SqliteDropCreateDatabaseAlways
      • SqliteDropCreateDatabaseWhenModelChanges
    2. Get more control by using one of the following two classes:

      • SqliteSqlGenerator (creates the SQL based on a EdmModel)
      • SqliteDatabaseCreator (creates a new SQLite database based on a Database and DbModel)

    Edit (30.05.2020): As EF 6 now supports .NET Core 3 and above, I adjusted the library to support .NET Standard 2.1 as well. The following .NET framework versions are supported:

    • .NET 4.0 (uses net40)
    • .NET 4.5-4.8 (uses net45)
    • .NET Core 3.0-3.1 (uses netstandard2.1)

提交回复
热议问题