System.Data.SQLite
View Ticket
Not logged in
Ticket UUID: c8083867b97b8862e81bfd1e4926a3d124c2ee09
Title: Support Entity Framework 4
Status: Closed Type: Feature_Request
Severity: Important Priority: Medium
Subsystem: LINQ Resolution: Overcome_By_Events
Last Modified: 2014-03-11 23:13:20
Version Found In: trunk
Description:
SQLite currently does not fully support Entity Framework 4.0, notably the CreateDatabase(), DatabaseExists() and DeleteDatabase() methods in its DbProviderServices, without which it is not possible to initialize the database via "Code First".

If these three methods would work with SQLite, it would be very useful for unit testing, as it is the only database engine that supports pure memory-backed databases (via "Data Source=:memory:"), making it easy to allow unit tests for the DB mapping layer to run in parallel to each other.


anonymous added on 2012-01-26 09:29:47 UTC:
Here's a chunk of example code for EF 4.2 that reproduces the errors:

public class Post {
	public string Title { get; set; }
}
public class BlogContext : DbContext {
	public BlogContext() : base(nameOrConnectionString: "BlogConnection") { }
	public DbSet<Post> Posts { get; set; }
}
class Program {
	static void Main(string[] args) {
		Database.SetInitializer<BlogContext>(
			new CreateDatabaseIfNotExists<BlogContext>()
		);
		using(var context = new BlogContext()) {
			context.Posts.Add(new Post() { Title = "Test" });
			context.SaveChanges();
		}
	}
}

Of course, the appropriate App.config needs to be in place:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<system.data>
		<DbProviderFactories>
			<remove invariant="System.Data.SQLite" />
			<add
				name="SQLite Data Provider"
				invariant="System.Data.SQLite"
				description="Data Provider for SQLite"
				type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"
			/>
		</DbProviderFactories>
	</system.data>
	<connectionStrings>
		<add
			name="BlogConnection"
			providerName="System.Data.SQLite"
			connectionString="Data Source=:memory:"
		/>
	</connectionStrings>
</configuration>
User Comments:
anonymous (claiming to be morpheus_xx) added on 2013-06-25 05:35:36:

Is there any news about this issue? I plan to use SQLite in a EF4 "Code First" project, but due to this missing feature I can't do so.

During my investigation I found following background:

1) ObjectContext.CreateDatabase is used to create a new database (http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.createdatabasescript.aspx). It is stated in docs, that: "most work is delegated to:"

2) DbProviderServices.CreateDatabase Method (http://msdn.microsoft.com/en-us/library/system.data.common.dbproviderservices.createdatabase.aspx)

3) But there is already a SQLiteProviderServices class that derives from DbProviderServices (http://system.data.sqlite.org/index.html/artifact/d69370467b6ce499f16026c7b2e54332990be6aa)

So what else is missing? How much effort it would take to implement the missing features?

I really would like to have a version that works with "Code First" EF feature!

Thank you very much!


anonymous added on 2013-06-28 05:57:40:
Found some more information that may be helpful

http://archive.msdn.microsoft.com/EFSampleProvider, the source code can be downloaded

mistachkin added on 2014-03-11 23:13:20:
The Entity Framework 6 is now supported.