PandaTech.NpgsqlBinaryCopyHelper
1.0.3
Pandatech.EFCore.PostgresExtensions
Additional DetailsWe have moved our extension class to another nuget package. All updates are going to be there and syntax has been simplified. Also it has bug fixes there.
dotnet add package PandaTech.NpgsqlBinaryCopyHelper --version 1.0.3
NuGet\Install-Package PandaTech.NpgsqlBinaryCopyHelper -Version 1.0.3
<PackageReference Include="PandaTech.NpgsqlBinaryCopyHelper" Version="1.0.3" />
paket add PandaTech.NpgsqlBinaryCopyHelper --version 1.0.3
#r "nuget: PandaTech.NpgsqlBinaryCopyHelper, 1.0.3"
// Install PandaTech.NpgsqlBinaryCopyHelper as a Cake Addin #addin nuget:?package=PandaTech.NpgsqlBinaryCopyHelper&version=1.0.3 // Install PandaTech.NpgsqlBinaryCopyHelper as a Cake Tool #tool nuget:?package=PandaTech.NpgsqlBinaryCopyHelper&version=1.0.3
Pandatech.NpgsqlBinaryCopyHelper
Hi! Pandatech.NpgsqlBinaryCopyHelper is a powerful NuGet package that simplifies binary copy operations using Npgsql in .NET applications. It provides a convenient and strongly typed API to streamline the insertion of data into a PostgreSQL database using the binary copy feature.
Features
- Strongly Typed Models: Supports strongly typed models for easy binary copy operations.
- Insertion Options: Provides options to insert data with or without code-generated unique IDs for each model.
- Simplified Usage: Streamlines the process of writing raw SQL statements, opening and closing connections, and handling exceptions.
- Logging Support: Offers logging capabilities for debugging and troubleshooting.
- Asynchronous Operations: Supports asynchronous operations for better performance.
Installation
You can install the Pandatech.NpgsqlBinaryCopyHelper package via NuGet package manager or by using the .NET CLI.
dotnet add package PandaTech.NpgsqlBinaryCopyHelper
Usage
The Pandatech.NpgsqlBinaryCopyHelper
package enhances the native Npgsql binary copy functionality with strongly-typed
support. Follow the steps below to use the package effectively:
Import the Pandatech.NpgsqlBinaryCopyHelper
namespace:
using Pandatech.NpgsqlBinaryCopyHelper;
Set the logger (optional):
CopyHelper.SetLogger(logger);
Use this method to specify a logger that will be used to log debug, informational, and error messages during the binary copy process.
Perform the binary copy operation:
await modelList.CopyAsync(context, insertWithPrimaryKeys: false);
- modelList: A list of models to be inserted.
- context: The DbContext instance used to retrieve the database connection.
- insertWithPrimaryKeys (optional): Set to
true
if you want to insert the models with their primary keys. If set tofalse
, the primary keys will be ignored, and the database will generate unique IDs for each model. The default isfalse
.
Note: The binary copy operation is a heavy operation, so exercise caution when using it. Ensure that the list of models is not null or empty and that the DbContext instance is properly initialized.
Example
Assuming you have a model class named Person:
public class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
And you have a list of Person models:
var personList = new List<Person>
{
new Person { Id = 1, Name = "John" },
new Person { Id = 2, Name = "Jane" }
};
To perform a binary copy using the Pandatech.NpgsqlBinaryCopyHelper
:
using (var context = new MyDbContext())
{
await personList.CopyAsync(context, insertWithPrimaryKeys: true);
}
Important Considerations
This library assumes that you are using Entity Framework Core (EF Core) with the Code First approach. It relies on the DbContext to retrieve the database connection string and execute the binary copy operation.
By default, this library uses the naming conventions retrieved from DbContext. If you have customized table or column names in the database, make sure they match the naming conventions in your code.
Caution: The binary copy operation performs bulk inserts directly into the database and bypasses certain validations and constraints. Ensure that the data being inserted is valid and consistent with the database schema.
It is recommended to thoroughly test the usage of this library and perform performance tests in your specific scenarios to ensure it meets your requirements.
Make sure to handle exceptions appropriately when using this library. Any exceptions thrown during the binary copy process should be caught and handled accordingly.
Troubleshooting
If you encounter any issues or have questions, feel free to reach out to the Pandatech.NpgsqlBinaryCopyHelper community for support.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net7.0
- FluentAssertions (>= 6.12.0)
- Microsoft.EntityFrameworkCore (>= 7.0.12)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 7.0.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|