I want to use NoSQL databases with ORM (PetaPoco, Dapper, EF Core) in my .NET 6 app. PetaPoco use connectionString and providerName, I just need to install the provider and that's it? The same situation with EF Core? I didn't find the information I needed in the documentation. Is there a list of supported databases?
PetaPoco:
using PetaPoco;
using WebAPI.Models;
namespace WebAPI.Data
{
public class PetaDb
{
private readonly Database db;
public PetaDb(string connectionString, string providerName)
{
db = new Database(connectionString, providerName);
}
public IEnumerable<EmployeeModel?> GetEmployee(Func<EmployeeModel?, bool> predicate)
{
return db.Query<EmployeeModel?>("SELECT * FROM Employees").Where(predicate);
}
}
}
Is it enought to install provider for MongoDB for example and just pass as a parameter in constructor or not?
Dapper:
using Dapper;
using System.Data;
using System.Data.SqlClient;
using WebAPI.Models;
namespace WebAPI.Data
{
public class DapperDb
{
private readonly string _connectionString;
public DapperDb(string connectionString)
{
_connectionString = connectionString;
}
public EmployeeModel? Get(Func<EmployeeModel?, bool> predicate)
{
using (IDbConnection conn = new SqlConnection(_connectionString))
{
return conn.Query<EmployeeModel?>("SELECT * FROM Employees").FirstOrDefault(predicate);
}
}
}
}
I just pass connectionString and always open new connection, is it enought to create MongoDB client and use Dapper or not?