ShimmyMySherbet.MySQL.EF 1.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ShimmyMySherbet.MySQL.EF --version 1.0.0
NuGet\Install-Package ShimmyMySherbet.MySQL.EF -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ShimmyMySherbet.MySQL.EF" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ShimmyMySherbet.MySQL.EF --version 1.0.0
#r "nuget: ShimmyMySherbet.MySQL.EF, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ShimmyMySherbet.MySQL.EF as a Cake Addin
#addin nuget:?package=ShimmyMySherbet.MySQL.EF&version=1.0.0

// Install ShimmyMySherbet.MySQL.EF as a Cake Tool
#tool nuget:?package=ShimmyMySherbet.MySQL.EF&version=1.0.0

MySQLEntityFramework

A Lightweight MySQL Entity Adapter for .NET

Usage

Basic usage of this library is centered around MySQLEntityClient. This class povides access to most SQL functions. When working with a table, you use a class associated with it. This class is also what you use to read/write entries from a database table.

For the following examples, this class is used:

public class UserAccount
{
    [SQLPrimaryKey, SQLAutoIncrement, SQLOmit]
    public int ID;

    [SQLUnique]
    public string Username;

    public byte[] HashData;

    [SQLIndex]
    public ulong SteamID;

    public string EmailAddress;

    public DateTime Created;
}

Creating the MySQLEntityClient

The MySQLEntityClient is used for most functions. If you need pure performance (sub 0.2ms for simple queries and inserts) you should use the SQLConverter and EntityCommandBuilder classes more specific methods rather than the Entity Client's generalised methods.

This Client has two modes, Single Connection mode and Multiple Connection mode.

In Single Connection Mode, a single SQL connection is made, and maintained. All methods in the client will use this single connection, locking it while it's in use. This means, in this mode, if multiple methods are invoked accross two or more threads, the methods will block until the connection is available. This mode is ideal for mostly single threaded screnarios that need to transfer alot of data (e.g., 50K queries in 4 sec on a single thread).

Multiple Connection Mode

In this mode, a new connection is made each time a connection is needed. This means that the client can be used accross many threads simultaneously without blocking.

This mode is ideal for database wrappers that will likely be accessed across multiple threads.

bool SingleConnectionMode = true;
MySQLEntityClient EntityClient = new MySQLEntityClient("127.0.0.1", "UserName", "SuperSecretPassword", "Database", 3306, SingleConnectionMode);

Console.WriteLine($"Connected: {EntityClient.Connected}");

From here on, this MySQLEntityClient will just be referanced as EntityClient in code snippets

Creating a Database Table

This uses the model of the supplied class, including any SQL attributes on it's fields, to create an equivilant database table.

EntityClient.CreateTable<UserAccount>("Users");

Querying

Selecting multiple entries:

List<UserAccount> Accounts = EntityClient.Query<UserAccount>("SELECT * FROM Users");

Selecting a single entry:

This method returns null if there are no results.

UserAccount userAccount1 = EntityClient.QuerySingle<UserAccount>("SELECT * FROM Users WHERE ID = 1");

Using Parameters

Most of MySQLEntityClient's methods provide an easy way to create command parameters. Parameters are a feature of MySQL.Data that allows you to securely represent a variable in a MySQLCommand. These parameters safely format and escape the variable, to prevent SQL injection attacks and ensure proper query formatting. These should be used when working with strings or class types (e.g., DateTime).

UserAccount BobsAccount = EntityClient.QuerySingle<UserAccount>("SELECT * FROM Users WHERE Username = @0 AND EmailAddresss = @1", "Bob", "BobsMail@mail.com");

Inserting

Since the ID field of UserAccount has sQLOmit, it is omitted from the insert. This means that the value will resolve to the default value. In this case, since it is also tagged as AutoIncrement when the table was created, it will resolve to the new auto-increment value.

UserAccount NewAccount = new UserAccount()
{
   Username = "NewUser",
   EmailAddress = "Email@Address.com",
   SteamID = 123456789,
   Created = DateTime.Now,
   HashData = new byte[] { 10, 21, 21 }
};
EntityClient.Insert(NewAccount, "Users");

Updating

This method requires that the supplied object's class has a field tagged as SQLPrimaryKey.

BobsAccount.EmailAddress = "BobsNewEmailAddress@email.com";
EntityClient.Update(BobsAccount, "Users");

Deleting

This method requires that the supplied object's class has a field tagged as SQLPrimaryKey.

EntityClient.Delete(BobsAccount, "Users");

Checking for a table

This method allows you to check if a table exists by it's name in the current database.

if (EntityClient.TableExists("Users"))
{
  Console.WriteLine("Table Exists.");
} else
{
  Console.WriteLine("Tabe does not exist.");
}

Checking Connection Status

If ReuseSingleConnection (Single Connection Mode) is enabled, it will return the connection status of the active MySQL connection. If the client is in Multiple Connection mode, this will attempt to create a new connection, and returns if the connection was successful.

if (EntityClient.Connected)
{
    Console.WriteLine("Connected!");
} else
{
    Console.WriteLine("Connection Failed.");
}

Deleting a table

This method will drop a table and all of it's contents.

EntityClient.DeleteTable("Users");

SQL Attributes

For a full list of SQL Attribues, see the wiki page https://github.com/ShimmyMySherbet/MySQLEntityFramework/wiki/SQL-Attributes

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ShimmyMySherbet.MySQL.EF:

Package Downloads
Hath.PlayerStats

Enriches your server by saving and displaying player statistics. a range of in-game performance metrics, and other pertinent data.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.8.9 348 11/4/2023
1.8.9-beta 109 10/7/2023
1.8.8 688 5/7/2022
1.8.7 433 5/6/2022
1.8.6 439 3/20/2022
1.8.5 422 3/11/2022
1.8.2 576 1/19/2022
1.8.0 309 12/25/2021
1.6.7 436 7/15/2021
1.6.5 509 7/15/2021
1.6.3 451 6/25/2021
1.6.0 433 6/5/2021
1.5.5 410 6/2/2021
1.5.2 511 5/30/2021
1.5.0 397 5/25/2021
1.4.2 480 5/24/2021
1.4.0 383 5/24/2021
1.3.0 424 5/15/2021
1.2.5 453 4/7/2021
1.2.0 441 4/3/2021
1.0.0 512 7/26/2020