dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.71k stars 3.17k forks source link

Does a custom EF Core provider require DbConnection? #16232

Closed nicolasr75 closed 1 year ago

nicolasr75 commented 5 years ago

I know this is not an 'issue' with EF Core but a question. The question is probably so exotic, however, that I thought only people from the EF Core team may know the answer directly.

I would like to write a custom database provider for a rather old database system (FlashFiler2). The purpose here is to enable my team to write new frontend software that connects to existing databases via EF Core. Later on we want to replace the existing databases by PostgreSQL or MS SQL Server step by step. The frontend software then would ideally only need to exchange the provider.

I studied the provider for SQL Server Compact by ErikEJ and started to study the SQLite provider. Both of these use a class derived from System.Data.DbConnection. Is that a requirement? Should I, as a first step, wrap my C API in a custom System.Data.DbConnection?

Further technical details

EF Core version: 2.2.4 Database Provider: custom Operating system: Windows 10, Windows Server 2016 IDE: Visual Studio 2019

ajcvickers commented 5 years ago

@nicolasr75 There are two broad categories of EF Core database providers. The first kind are what we call "relational providers", which really means providers that are based on ADO.NET types like DbConnection. The second type are known as "non-relational providers" which really means that they don't use ADO.NET.

While saying "relational" and "non-relational" is convenient, there is no reason why a "non-relational" provider cannot target a relational database that doesn't use ADO.NET.

That being said, relational providers are much more common and share a lot of infrastructure because they all use the ADO.NET types. This means non-relational providers are more work to create. Also, there are fewer examples--in our code base the two examples to look at are the in-memory provider and the Cosmos provider.

So yes, it can be done, but it probably won't be super easy.

nicolasr75 commented 5 years ago

Perfect! Thanks for the explanation.