GameVerse.UniversalDataAccess
1.3.0
dotnet add package GameVerse.UniversalDataAccess --version 1.3.0
NuGet\Install-Package GameVerse.UniversalDataAccess -Version 1.3.0
<PackageReference Include="GameVerse.UniversalDataAccess" Version="1.3.0" />
<PackageVersion Include="GameVerse.UniversalDataAccess" Version="1.3.0" />
<PackageReference Include="GameVerse.UniversalDataAccess" />
paket add GameVerse.UniversalDataAccess --version 1.3.0
#r "nuget: GameVerse.UniversalDataAccess, 1.3.0"
#:package GameVerse.UniversalDataAccess@1.3.0
#addin nuget:?package=GameVerse.UniversalDataAccess&version=1.3.0
#tool nuget:?package=GameVerse.UniversalDataAccess&version=1.3.0
UniversalDataAccess
UniversalDataAccess is a versatile and easy-to-use NuGet package that provides generic CRUD (Create, Read, Update, Delete) operations for working with any relational database. It supports both direct SQL commands via System.Data.SqlClient
and Entity Framework's DbContext
, allowing seamless integration into your WPF .NET Framework projects.
Features
- Perform CRUD operations on any table with dynamic schemas.
- Supports direct database access via
System.Data.SqlClient
. - Compatible with Entity Framework
DbContext
for ORM-based interactions. - Fully adaptable to any database system that uses SQL (e.g., SQL Server, MySQL, PostgreSQL, etc.) with minimal modifications.
- Simple API designed for flexibility and ease of use.
Includes
The package includes:
- Methods for retrieving database schema and data as dictionaries
- Insert, update, and delete operations for database records
- Utilities for formatting phone numbers and validating passwords
- Flexible connection handling via connection strings, DbContext, or SqlConnection
Features
- Retrieve database schema and data structure
- Perform CRUD operations (Create, Read, Update, Delete)
- Format phone numbers from raw 11-digit strings to international format +7 (xxx) xxx-xx-xx
- Validate passwords with various rules (length, presence of digits, letters, special symbols)
- Obtain connection strings from different sources
Getting Started
Installation
Install UniversalDataAccess via NuGet Package Manager:
- powershell
- Install-Package UniversalDataAccess
Usage
1. Get Database Schema
// Retrieve database schema (tables and columns)
SqlClient sqlClient = new SqlClient();
var schema = SqlClient.GetTableSchema(ConnectionOrStringOrContext, "Users");
- Input: connection string (string) or DbContex or SqlConnection, and table name
- Output: Dictionary<string, List<string>> where key is table name, value is list of column names
2. Get Data Dictionary
// Get all data from a table
SqlClient sqlClient = new SqlClient();
var data = SqlClient.CreateDataDictionary(ConnectionOrStringOrContext, "Users");
- Input: connection string (string) or DbContex or SqlConnection, and table name
- Output: List of strings, each representing a row in the table
3. Insert Record
// Insert new record into "Users" table
SqlClient sqlClient = new SqlClient();
var newRecord = new Dictionary<string, object>();
data["Name"] = "John";
data["Phone"] = "+7 (900) 123-45-67";
data["Age"] = "30";
SqlClient.InsertRecord(ConnectionOrStringOrContext, "Users", newRecord);
- Input: connection string (string) or DbContex or SqlConnection, and table name, dictionary of field-value pairs
- Output: void, record is inserted
4. Update Record
// Update record where ID=5
SqlClient sqlClient = new SqlClient();
var updateFields = new Dictionary<string, object>();
data["Age"] = "75";
SqlClient.UpdateRecord(ConnectionOrStringOrContext, "Users", updateFields, "ID", "5");
- Input: connection string (string) or DbContex or SqlConnection, and table name, dictionary fields to update, primary key field name, ID value
- Output: void, record is updated
5. Delete Record
// Delete record where ID=5
SqlClient sqlClient = new SqlClient();
SqlClient.DeleteRecord(ConnectionOrStringOrContext, "Users", "ID", "5");
- Input: connection string (string) or DbContex or SqlConnection, and table name, primary key field name, ID value
- Output: void, record is deleted
6. Format Phone Number
string rawPhone = "89902202450";
string formattedPhone = DataConverter.FormatPhoneNumber(rawPhone);
Console.WriteLine(formattedPhone); // +7 (900) 220-24-50
- Input: raw number string with 11 digits
- Output: formatted phone number
7. Convert DateTime For DB
DateTime? date1 = DataConverter.ConvertToDateTime("2024.05.23", true);
// date1 will be 2024-05-23 00:00:00
DateTime? date2 = DataConverter.ConvertToDateTime("2024.05.23 15:30:00", false);
// date2 will be 2024-05-23 15:30:00
DateTime? invalid = DataConverter.ConvertToDateTime("3024.01.01", true);
// invalid will be null (year is out of allowed range)
- Input: date, condition
- Output: formatted date
8. Get BitmapImage From Resource
image.Source = DataConverter.GetBitmapImageFromResource("Resources", "logo.png");
// Loads Images/logo.png from your project resources as a BitmapImage
- Input: image folder name, file name
- Output: BitmapImage object
9. Password Validation
bool isValid = ValidatorClass.ValidatePassword(
"MyP@ssw0rd",
minLength: 4,
maxLength: 12,
requireDigit: true,
requireLetter: true,
requireSpecial: true),
notEmpty: true;
Console.WriteLine($"Password is valid: {isValid}");
- Input: password string, validation rules
- Output: true if valid, otherwise false
10. Login Validation
bool isValid = ValidatorClass.ValidateLogin(
"MyLogin123",
minLength: 4,
maxLength: 12,
requireLetter: true,
notEmpty: true);
Console.WriteLine($"Login is valid: {isValid}");
- Input: login string, validation rules
- Output: true if valid, otherwise false
11. Phone Validation
bool valid = ValidatorClass.IsValidPhone("+71234567890"); // returns true
bool invalid = ValidatorClass.IsValidPhone("81234567890"); // returns false
- Input: phone string
- Output: true if valid, otherwise false
12. Email Validation
bool valid = ValidatorClass.IsValidEmail("user@example.com"); // returns true
bool invalid = ValidatorClass.IsValidEmail("user@@example..com"); // returns false
- Input: email string
- Output: true if valid, otherwise false
13. Get ConnectionString
// From raw string
SqlClient sqlClient = new SqlClient();
string connStr = SqlClient.GetConnectionString("your-connection-string");
// From DbContext
SqlClient sqlClient = new SqlClient();
using (var context = new YourDbContext())
{
string connStrFromContext = SqlClient.GetConnectionString(context);
}
// From SqlConnection
SqlClient sqlClient = new SqlClient();
using (var connection = new SqlConnection(connStr))
{
string connStrFromConnection = SqlClient.GetConnectionString(connection);
}
- Input: connection string (string) or DbContex or SqlConnection
- Output: connection string (string)
Important Notes
- All database methods require a valid connection string or objects (DbContext, SqlConnection).
- For security, avoid SQL injection when constructing conditions.
- Password and phone formatting methods are examples and may need adjustments for specific requirements.
Contributing
Contributions are welcome! Please submit pull requests or open issues on GitHub.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. net48 is compatible. net481 was computed. |
-
.NETFramework 4.8
- Microsoft.AspNet.WebApi.Client (>= 5.2.7)
- Microsoft.EntityFrameworkCore.SqlServer (>= 3.1.32)
- Newtonsoft.Json (>= 10.0.1)
- System.Buffers (>= 4.5.1)
- System.Data.SqlClient (>= 4.9.0)
- System.Diagnostics.DiagnosticSource (>= 4.7.1)
- System.Memory (>= 4.5.4)
- System.Numerics.Vectors (>= 4.5.0)
- System.Runtime.CompilerServices.Unsafe (>= 4.7.1)
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 |
---|---|---|
1.3.0 | 477 | 7/24/2025 |
WARNING! This package is currently under development.