To install Rapidex.Data from NuGet Package Manager Console in Visual Studio.
Install-Package Rapidex.Dataand the database provider package for your database engine, for example, for SQL Server:
Install-Package Rapidex.Data.SqlServerFirst, you need to configure the database connection (appsettings.json)
{
"Rapidex": {
"Databases": {
"Master": {
"Provider": "Rapidex.Data.SqlServer.DbSqlServerProvider",
"ConnectionString": "Data Source=databaseServer;Initial Catalog=databaseName;User Id=username;Password=userPassword;MultipleActiveResultSets=true;Pooling=true;Min Pool Size=10; Max Pool Size=500;TrustServerCertificate=True"
}
},
"Policies": {
"MaxRetryCount": 5,
"WaitForRetryMs": 1000
},
"Cache": {
"InMemory": {
"ItemLimit": 5000,
"AbsoluteExpiration": 600, //seconds
"SlidingExpiration": 500
},
"Distributed": { //Remove if not used.
"Type": "Redis",
"ConnectionString": "redisConnectionString",
"Expiration": 6000, //seconds
"LocalExpiration": 600 //seconds
}
}
}
}or
{
"Rapidex": {
"Databases": {
"Master": {
"Provider": "Rapidex.Data.PostgreServer.PostgreSqlServerProvider",
"ConnectionString": "User ID=username;Password=userPassword;Host=databaseServer;Port=5432;Database=databaseName;"
}
},
"Policies": {
"MaxRetryCount": 5,
"WaitForRetryMs": 1000
},
"Cache": {
"InMemory": {
"ItemLimit": 5000,
"AbsoluteExpiration": 600, //seconds
"SlidingExpiration": 500
},
"Distributed": { //Remove if not used.
"Type": "Redis",
"ConnectionString": "redisConnectionString",
"Expiration": 6000, //seconds
"LocalExpiration": 600 //seconds
}
}
}
}You can define your entities using concrete classes or JSON/YAML files. Here is an example of defining an entity using a concrete class:
public class Country : DbConcreteEntityBase
{
public string Name { get; set; }
public string Code { get; set; }
public string Iso2 { get; set; }
public string Iso3 { get; set; }
public string CurrencySymbol { get; set; }
public string PhoneCode { get; set; }
}See: Entity Definition
See: Sample Application
var db = Database.Dbs.Db();
var countries = db.GetQuery<Country>()
.Like(nameof(Country.Name), "Uni%")
.OrderBy(OrderDirection.Asc, nameof(Country.Name))
.Load();
// or
var work = db.BeginWork();
var newRecord = work.New<Country>();
newRecord.Name = "New Country";
newRecord.Save();
work.CommitChanges();See: Querying Data
See: Updating Data
Using Dependency Injection in your application, add Rapidex.Data services and start the infrastructure.
//...
builder.Services.AddRapidexDataLevel(); //<- Add Rapidex services
//...
app.Services.StartRapidexDataLevel(); //<- Start Rapidex infrastructure
//...
var db = Database.Dbs.AddMainDbIfNotExists();
db.Metadata.AddIfNotExist<Country>(); //Add definition with manual or declare *Library* and auto load all definitions
db.Structure.ApplyAllStructure();
app.Run();See: Library Declaration
See: Sample Application