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
<PackageReference Include="KullGames_ServerLists_EfModels" Version="1.0.20241028.964" />
paket add KullGames_ServerLists_EfModels --version 1.0.20241028.964
#r "nuget: KullGames_ServerLists_EfModels, 1.0.20241028.964"
// 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
, andServerTag
entities with comprehensive properties and data annotations. - Relationships: Establishes relationships between entities, such as one-to-many between
User
andServer
, and many-to-many betweenServer
andServerTag
. - 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:
Add Migration
dotnet ef migrations add InitialCreate --project KullGames_ServerLists_EfModels --startup-project YourStartupProject
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 forUsers
,Servers
, andServerTags
. Configures entity relationships and database-specific settings. - Entities:
User.cs
: Represents a user with properties likeUsername
,Email
, and navigation propertyServers
.Server.cs
: Represents a server with properties likeName
,IPAddress
,Port
,OwnerId
, and navigation propertiesOwner
andServerTags
.ServerTag.cs
: Represents a server tag with properties likeTagName
and navigation propertyServers
.
Building the Project
To build the project locally, follow these steps:
Clone the Repository
git clone https://dev.azure.com/KullGamesRepo/KullGames/_git/KullGames_ServerLists
Navigate to the Project Directory
cd KullGames_ServerLists/KullGames_ServerLists_EfModels
Restore Dependencies and Build
dotnet restore dotnet build
Contributing
Contributions are welcome! Please follow the steps below:
Fork the Repository
Create a New Branch
git checkout -b feature/your-feature
Commit Your Changes
git commit -am 'Add some feature'
Push to the Branch
git push origin feature/your-feature
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 | Versions 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. |
-
net8.0
- KullGames_ServerLists_Localization (>= 1.0.20241028.964)
- Microsoft.EntityFrameworkCore (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Abstractions (>= 8.0.10)
- Microsoft.EntityFrameworkCore.InMemory (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Sqlite (>= 8.0.10)
- Microsoft.EntityFrameworkCore.Sqlite.Core (>= 8.0.10)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.10)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.10)
- Pomelo.EntityFrameworkCore.MySql (>= 8.0.2)
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 | 124 | 10/28/2024 |
Initial release.