MySqlDbController 1.7.8
See the version list below for details.
dotnet add package MySqlDbController --version 1.7.8
NuGet\Install-Package MySqlDbController -Version 1.7.8
<PackageReference Include="MySqlDbController" Version="1.7.8" />
<PackageVersion Include="MySqlDbController" Version="1.7.8" />
<PackageReference Include="MySqlDbController" />
paket add MySqlDbController --version 1.7.8
#r "nuget: MySqlDbController, 1.7.8"
#:package MySqlDbController@1.7.8
#addin nuget:?package=MySqlDbController&version=1.7.8
#tool nuget:?package=MySqlDbController&version=1.7.8
Main features
This library allows you to conveniently and abstractly work with MySQL databases and tables. Using attributes, it determines which class properties to use when executing queries, how to fill them out, and how to read them. The library also provides the ability to create a table in the database based on a class filled with special attributes, and the ability to create a class file based on a table in the database. After creation, such a file contains a class with the necessary attributes for further work with this library, properties of the desired type, a default constructor, and, optionally, a manual constructor.
Working with a finished table
For the full work of your model with a table in the database, you need to use the Table and Column attributes. Table - an attribute that declares the name of the table in the database. Column - an attribute declaring the name of the column, as well as the presence and method of conversion enumeration, if the associated property is one. There are three simple rules for building a model that will work with our library:
- all entity classes should be inherited from the DbObject class, which contains the Id property required by each table in MySQL;
- both the class and properties must be public (properties must have a public setter);
- all entity classes must have a public constructor without parameters.
This is how it looks in code:
namespace Test
{
[Table("vat.man")]
class Man : DbObject<int>
{
[Column("lastname")]
public string Lastname { get; set; }
[Column("age")]
public int Age { get; set; }
[Column("test_enum", true, typeof(Position), EnumConvertionMode.INT)]
public Position TestEnum { get; set; }
public Man() { }
}
After this formal part, you can create an instance of the controller:
var controller = new DbController<Man, int>("localhost", "admin", "qwerty");
In the type parameters, you need to specify the entity and type of the identifier (int or long for example). Of the required: host address, username, and password. The controller constructor has many parameters, but most of them have a default value. I think users who have been working with MySQL for a long time will understand everything from the comments in the code. Now we have many interesting methods available: List<Entity> Select(), Entity SelectById(IdType id), void Insert(Entity cortege), void Update(Entity cortege), int Delete(IdType id).
"CodeFirst" and "DBFirst"
To save your time, we wrote an algorithm that creates a MySQL table based on a written class and generates a class file based on an existing table. For the library to be able to create the table, you must use the ColumnSettings attribute for the properties. The parameters of this attribute indicate the data type, dimension, default value, and more. Take a look at the code below:
namespace Test
{
[Table("Man")]
class Man : DbObject<int>
{
[Column("lastname")]
[ColumnSettings(ColumnDataType.VARCHAR, 255, "Smith", true)]
public string Lastname { get; set; }
[Column("age")]
[ColumnSettings(ColumnDataType.INT, 11, 30, true)]
public int Age { get; set; }
[Column("test_enum", true, typeof(Position), EnumConvertionMode.INT)]
[ColumnSettings(ColumnDataType.INT)]
public Position TestEnum { get; set; }
public Man() { }
}
}
Now, you need to create an instance of the controller and call the CreateTableIfNotExists method.
To create a class file, use the CreateClassFile method, which is located in the root class and does not require type parameters:
void CreateClassFile(destinationPath, tableName, nameSpace, true);
Unfortunately, for now, the class is not automatically added to the project. We are working on a VSIX extension with this functionality.
Product | Versions 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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- MySql.Data (>= 8.0.17)
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 |
---|---|---|
2.0.2 | 190 | 4/7/2024 |
2.0.1 | 682 | 7/28/2020 |
2.0.0 | 562 | 7/22/2020 |
1.8.1 | 576 | 7/6/2020 |
1.8.0 | 581 | 6/2/2020 |
1.7.9 | 629 | 5/8/2020 |
1.7.8 | 681 | 4/10/2020 |
1.7.7 | 638 | 4/10/2020 |
1.7.6 | 634 | 4/10/2020 |
1.7.5 | 659 | 4/10/2020 |
1.7.4 | 643 | 4/10/2020 |
1.7.3 | 611 | 4/9/2020 |
1.7.2 | 656 | 4/8/2020 |
1.7.1 | 591 | 4/7/2020 |
1.7.0 | 565 | 4/7/2020 |
1.6.16 | 607 | 3/24/2020 |
1.6.15 | 622 | 3/24/2020 |
1.6.14 | 629 | 2/17/2020 |
1.6.13 | 620 | 2/17/2020 |
1.6.12 | 571 | 2/17/2020 |
1.6.11 | 629 | 2/7/2020 |
1.6.10 | 615 | 2/7/2020 |
1.6.9 | 623 | 1/21/2020 |
1.6.8 | 598 | 1/17/2020 |
1.6.7 | 634 | 12/18/2019 |
1.6.6 | 651 | 12/18/2019 |
1.6.5 | 624 | 12/18/2019 |
1.6.2 | 630 | 11/8/2019 |
1.6.1 | 626 | 11/8/2019 |
1.6.0 | 639 | 10/11/2019 |
1.5.5 | 652 | 10/11/2019 |
1.5.4 | 705 | 9/19/2019 |
1.5.3 | 664 | 9/13/2019 |
1.5.2 | 649 | 9/5/2019 |
1.5.1 | 664 | 9/4/2019 |
1.5.0 | 693 | 8/20/2019 |
1.4.0 | 730 | 8/8/2019 |
1.3.1 | 744 | 8/7/2019 |
1.3.0 | 666 | 8/7/2019 |
1.2.0 | 711 | 8/6/2019 |
1.1.0 | 702 | 8/5/2019 |
1.0.0 | 700 | 8/5/2019 |