SQLKata.EntityKata 1.0.6-alpha

This is a prerelease version of SQLKata.EntityKata.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package SQLKata.EntityKata --version 1.0.6-alpha
NuGet\Install-Package SQLKata.EntityKata -Version 1.0.6-alpha
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="SQLKata.EntityKata" Version="1.0.6-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SQLKata.EntityKata --version 1.0.6-alpha
#r "nuget: SQLKata.EntityKata, 1.0.6-alpha"
#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 SQLKata.EntityKata as a Cake Addin
#addin nuget:?package=SQLKata.EntityKata&version=1.0.6-alpha&prerelease

// Install SQLKata.EntityKata as a Cake Tool
#tool nuget:?package=SQLKata.EntityKata&version=1.0.6-alpha&prerelease

SQLKata.EntityKata

Entity Modeler using SQLKata

The idea is to focus the code using only entities names instead of SQL queries to model the data, to reduce errors abstract the logic. The library is based on SQLKata and does all the translations under the hood.

Especially useful when entities and database columns have different names. If a property doesn't have the field attribute it will be skipped.

This is the first release for optimization and testing.

More methods (and examples) will be added soon.

Using entity Person that represents a record in table People

// a separated class form identity can be convenient
[Table("People")]
public class PersonIdentity
{
    [Identity]
    [Field("PersonId")]
    public int Id { get; set; }
}

[Table("People")]
public class Person : PersonIdentity 
{

    [Field("PersonName")]
    public string FirstName { get; set; }
    [Field("PersonLastName")]
    public string LastName { get; set; }
    [Field("PersonAge")]
    public int Age { get; set; }
    [Field("PersonPhone")]
    public string Phone { get; set; }
    [Field("PersonEmail")]
    public string Email { get; set; }
}

var env = new EntityKataService(new MySqlConnection("Server=localhost;Database=entitkatatest;Uid=root;Pwd=;")
    , new MySqlCompiler());

var peopleManager = env.New<Person>();

var people = peopleManager.Get();

foreach(var person in people) {
    Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
}

// if you have a separated Id class you can use it, otherwise 
// you can use an anonymous class
// Both of the following are valid    
people = peopleManager.Where(new Person {Id = 2}).Get();
people = peopleManager.Where(new {Id = 2}).Get();

people = peopleManager
    .OrderBy(nameof(Person.LastName))
    .Where(new {FirstName = "Gianpiero"})
    .Get();

var insertedRows = peopleManager.Insert(new Person
{
    Age = 33,
    Email = "onon@test.com",
    FirstName = "Marlon",
    LastName = "Bereny",
    Phone = "374873434"
});

Console.WriteLine("Inserted rows: " + insertedRows);

// you can use the same manager for the same type 
// you don't need to create a new one

peopleManager
    .Where(new PersonIdentity {Id = 2})
    .Update(new
    {
        FirstName = "John", 
        LastName = "Smith"
    });

if (peopleManager.Where(new {LastName = "Bereny"}).Exists()) {
    Console.WriteLine("Found Bereny");
    var deletedRows = peopleManager.Where(new {FirstName = "Marlon"}).Delete();
    Console.WriteLine("Deleted rows: " + deletedRows);
}

var firstPersonSmith = peopleManager
    .Where(new {LastName = "Smith"})
    .FirstOrDefault();

if (firstPersonSmith != null) {
    Console.WriteLine("First person with Smith last name: " + firstPersonSmith.FirstName);
}

people = peopleManager
    .OrderByDesc(nameof(Person.LastName))
    .Get();

foreach(var person in people) {
    Console.WriteLine("{0} {1}", person.FirstName, person.LastName);
}

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 netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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

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.1.1-alpha 134 7/24/2022
1.1.0-alpha 108 7/23/2022
1.0.7-alpha 105 7/23/2022
1.0.6-alpha 103 7/23/2022
1.0.5-alpha 104 7/19/2022
1.0.4-alpha 102 7/19/2022
1.0.3-alpha 105 7/19/2022
1.0.2-alpha 96 7/19/2022
1.0.1-alpha 90 7/19/2022
1.0.0-alpha 105 7/18/2022