KullGames_ServerLists_EfModels 1.0.20241028.964

dotnet add package KullGames_ServerLists_EfModels --version 1.0.20241028.964                
NuGet\Install-Package KullGames_ServerLists_EfModels -Version 1.0.20241028.964                
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="KullGames_ServerLists_EfModels" Version="1.0.20241028.964" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KullGames_ServerLists_EfModels --version 1.0.20241028.964                
#r "nuget: KullGames_ServerLists_EfModels, 1.0.20241028.964"                
#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 KullGames_ServerLists_EfModels as a Cake Addin
#addin nuget:?package=KullGames_ServerLists_EfModels&version=1.0.20241028.964

// Install KullGames_ServerLists_EfModels as a Cake Tool
#tool nuget:?package=KullGames_ServerLists_EfModels&version=1.0.20241028.964                

KullGames_ServerLists_EfModels

Overview

The KullGames_ServerLists_EfModels library is a .NET 8.0 project that defines the Entity Framework Core (EF Core) models and the ServerListDbContext for the KullGames Server Lists application. This project encapsulates the data schema and relationships for Users, Servers, and ServerTags, facilitating seamless interaction with the underlying database.

Features

  • Entity Definitions: Defines User, Server, and ServerTag entities with comprehensive properties and data annotations.
  • Relationships: Establishes relationships between entities, such as one-to-many between User and Server, and many-to-many between Server and ServerTag.
  • Multiple Database Support: Configured to support various databases including MySQL, PostgreSQL, SQLite, SQL Server, Firebird, In-Memory, and Cosmos DB.
  • Database Initialization: Automatically ensures the database is created and applies necessary configurations upon context initialization.
  • Data Annotations: Utilizes data annotations for validation and schema configuration, ensuring data integrity and consistency.

Requirements

  • .NET 8.0 SDK
  • Entity Framework Core 8.0+
  • Compatible Database Provider (e.g., MySQL, PostgreSQL, SQLite)

Installation

Add the KullGames_ServerLists_EfModels library to your project by referencing it in your .csproj file:

<ProjectReference Include="..\KullGames_ServerLists_EfModels\KullGames_ServerLists_EfModels.csproj" />

Ensure that you have the necessary EF Core packages installed for your chosen database provider. For example, for MySQL:

dotnet add package Pomelo.EntityFrameworkCore.MySql

Usage

Setting Up the DbContext

Instantiate the ServerListDbContext with the appropriate DbContextOptions. Here's an example using MySQL:

using KullGames_ServerLists_EfModels;
using Microsoft.EntityFrameworkCore;

var optionsBuilder = new DbContextOptionsBuilder<ServerListDbContext>();
optionsBuilder.UseMySql("your-connection-string", ServerVersion.AutoDetect("your-connection-string"));

using var context = new ServerListDbContext(optionsBuilder.Options);

Performing Migrations

To create and apply migrations, use the following commands:

  1. Add Migration

    dotnet ef migrations add InitialCreate --project KullGames_ServerLists_EfModels --startup-project YourStartupProject
    
  2. Update Database

    dotnet ef database update --project KullGames_ServerLists_EfModels --startup-project YourStartupProject
    

Sample Queries

Fetching Users
var users = await context.Users.ToListAsync();
foreach (var user in users)
{
    Console.WriteLine($"Username: {user.Username}, Email: {user.Email}");
}
Adding a New Server
var newServer = new Server
{
    Id = Guid.NewGuid(),
    Name = "Epic Minecraft Server",
    IPAddress = "192.168.1.200",
    Port = 25565,
    OwnerId = existingUserId,
    Description = "An epic server for all players!",
    Version = "1.20.1",
    Country = "US",
    Website = "https://epicserver.com",
    MaxPlayers = 100,
    CurrentPlayers = 10,
    Modpack = "SkyFactory 4",
    DiscordLink = "https://discord.gg/epicserver",
    Language = "English",
    UptimePercentage = 99.5
};

await context.Servers.AddAsync(newServer);
await context.SaveChangesAsync();
Deleting a ServerTag
var tag = await context.ServerTags.FindAsync(tagId);
if (tag != null)
{
    context.ServerTags.Remove(tag);
    await context.SaveChangesAsync();
}

Project Structure

  • ServerListDbContext.cs: Defines the ServerListDbContext with DbSets for Users, Servers, and ServerTags. Configures entity relationships and database-specific settings.
  • Entities:
    • User.cs: Represents a user with properties like Username, Email, and navigation property Servers.
    • Server.cs: Represents a server with properties like Name, IPAddress, Port, OwnerId, and navigation properties Owner and ServerTags.
    • ServerTag.cs: Represents a server tag with properties like TagName and navigation property Servers.

Building the Project

To build the project locally, follow these steps:

  1. Clone the Repository

    git clone https://dev.azure.com/KullGamesRepo/KullGames/_git/KullGames_ServerLists
    
  2. Navigate to the Project Directory

    cd KullGames_ServerLists/KullGames_ServerLists_EfModels
    
  3. Restore Dependencies and Build

    dotnet restore
    dotnet build
    

Contributing

Contributions are welcome! Please follow the steps below:

  1. Fork the Repository

  2. Create a New Branch

    git checkout -b feature/your-feature
    
  3. Commit Your Changes

    git commit -am 'Add some feature'
    
  4. Push to the Branch

    git push origin feature/your-feature
    
  5. Create a Pull Request

License

This project is licensed under the CC BY-NC 4.0 License - see the LICENSE file for full details.

You are free to:

- **Share**: Copy and redistribute the material in any medium or format.
- **Adapt**: Remix, transform, and build upon the material.

Under the following terms:

- **Attribution**: You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- **NonCommercial**: You may not use the material for commercial purposes.

Contact

For questions or support, please visit KullGames or open an issue in the repository.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on KullGames_ServerLists_EfModels:

Package Downloads
KullGames_ServerLists_DataAccess

A data access library which provides methods for reading and writing to a database.

KullGames_ServerLists_TestDataGenerator

A fake data generation library for KullGames Minecraft server listing.

KullGames_ServerLists_DataAccessClient

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.20241028.964 117 10/28/2024

Initial release.