Use Entity Framework 4.1 with SQLITE

Is it possible to? I have an existing database and created entity classes:

public class MyContainer : DbContext { public DbSet<Item> Items { get; set; } // more tables.. } 

When I use this connection string, it fails because it does not have metadata files:

  <connectionStrings> <add name="MyContainer" connectionString="metadata=.\items.csdl|.\items.ssdl|.\items.msl;provider=System.Data.SQLite;provider connection string=&quot;data source=.\mindstore.sqlite.s3db&quot;" providerName="System.Data.EntityClient"/> </connectionStrings> 

But when I omit the metadata from the configuration, it complains that you are not allowed to skip the metadata from the configuration.

So, how can you use SQLITE with EF 4.1 without any xml configuration files and just do a mapping for each convention?

+4
source share
1 answer

If you want to use EF code without EDMX first, you cannot use EntityClient . Use the standard ADO.NET connection string for SQLite:

 <connectionStrings> <add name="MyContainer" providerName="System.Data.SQLite" connectionString="data source=.\mindstore.sqlite.s3db" /> </connectionStrings> 

Edit:

To disable database creation and database validation, try deleting the standard metadata convention and setting the database initializer to zero.

Database Initializer:

 // call this only once in your application bootstrap Database.SetInitializer<YourContext>(null); 

Deleting an agreement:

 // Place this to your derived context protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreationg(modelBuilder); modelBuilder.Conventions.Remove<IncludeMetadataConvention>(); } 
+1
source

All Articles