Prisma provides a fast and easy way to implement a NoSQL db provider in your project.
-
Install the Prisma package in your project.
-
Register the service in your Startup.cs.
services.AddPrisma();
- Add the
PrismaOptions
to appsetting.json and register these.
{
"PrismaOptions":{
"Provider":"",
"ConnectionString":"",
}
}
services.Configure<PrismaOptions>(configuration.GetSection(nameof(PrismaOptions)));
Notice, that these options will change accordingly to the provider that you are using. Read the documentation on how to configure your provider below.
- Get the provider
IPrismaProvider<TEntity> myProvider = this.serviceProvider.GetRequiredService<IPrismaProvider<TEntity>>();
The PrismaProvider has the following methods:
- GetAsync
- InsertAsync
- UpdateAsync
- DeleteAsync
Notice, that all the entities that are used need to inherit from
BaseEntity
.
-
First and if you do not have an account create one here.
-
Create your organization and after that your project.
-
Configure your cluster, defining if this is accessible to anyone or not, and adding a database user.
-
Now, follow these steps.
-
Add the prisma options to your appsettings.json file, consider the following example.
{ "PrismaOptions":{ "Provider":"MongoDb", "ConnectionString":"mongodb+srv://admin:[email protected]/MyDatabaseName?retryWrites=true&w=majority" } }
-
First and if you haven't, create an account here.
-
Follow these steps to configure your account, see this.
-
Create a user, add it to the group that you have created, save the
Access Key ID
and theSecret access key
you will need this later on. -
Now, follow these steps.
-
Add the prisma options to your appsettings.json file, consider the following example.
{ "PrismaOptions": { "Provider": "DynamoDb", "ConnectionString": "accesskey=AKIATEJJHIIBH5Z6XUMA;secretkey=9VB7jBKQvdyNrVX5d2t+cD4UTwnW4Nc2f98vigHa;region=eu-west-1" } }
-
First and if you haven't, create an account here.
-
Now, follow these steps.
-
Add the prisma options to your appsettings.json file, consider the following example.
{ "PrismaOptions":{ "Provider":"CosmosDb", "ConnectionString":"AccountEndpoint=MyEndpoint;AccountKey=myAccountKey;DatabaseKey=myDatabaseKey;" } }
Notice, that you can define the throughput in your connection string by adding the following parameter
AutoscaleThroughput=value
orManualThroughput=value
in the connection string. By default the value of the throughput is set to 4000 RU/s.
The AutoScaleThroughput
, provisions the RU/s based on the workload between the range of 10% of Max RU/s to Max RU’s. Be aware that the cost of autoscale is 50% more than the standard throughput.
The ManualThroughput
, use this to define a custom value for your throughput.
To know more about this consider this article.
Also, you can define the partition key by adding the following parameter
PartitionKey=Name
in the connection string. By default the partition key is the entity id.