📚 OperatingSystem.cs Documentation
Assembly: IrbyImaging.DomainClasses
Namespace:IrbyImaging.DomainClasses
Author: kvamshi
Created: 03‑31‑2022
Last Modified: 03‑31‑2022
🗂 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Data Model: OperatingSystem Class
- Entity Framework Integration
- UML Class Diagram
- Sample Usage & Code Snippets
- Key Functional Areas
- Conclusion & Best Practices
🔍 Overview & Purpose
The OperatingSystem class models an operating system entry in the Irby Imaging domain. It serves as a lookup table in the database—for example, to populate drop‑down lists or to filter imaging tasks by supported operating systems.
- Main Goals
- Define the schema for the
irby.OperatingSystemtable. - Provide a simple, EF‑friendly POCO for CRUD operations.
- Indicate whether an OS option is currently available for selection.
- Define the schema for the
⚙️ Dependencies & Technologies
| Dependency | Purpose |
|---|---|
System |
Base .NET types (e.g., Int32, String, Boolean). |
System.ComponentModel.DataAnnotations |
Data‑annotation attributes ([Key], [Display]). |
System.ComponentModel.DataAnnotations.Schema |
Schema‑mapping attributes ([Table]). |
This class is intended for use with Entity Framework Core (or EF6) as part of the IrbyImaging domain model.
📦 Data Model: OperatingSystem Class
3.1 Class Declaration & EF Mapping
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.DomainClasses
{
[Table("OperatingSystem", Schema = "irby")]
public class OperatingSystem
{
// ... properties below ...
}
}
- [Table]
Maps this POCO to theirby.OperatingSystemtable in the database. - Schema:
irby - Table Name:
OperatingSystem
3.2 Properties
| Property Name | Type | Attributes | Description |
|---|---|---|---|
| Id | int |
[Key] |
Primary key. Unique identifier for each OS record. |
| Name | string |
— | Name or description (e.g., “Windows 10”, “Ubuntu 20.04”). |
| IsAvailableOption | bool |
[Display(Name = "Available?")] |
Flag indicating if this OS is currently an available choice. |
Display Name
The[Display(Name = "Available?")]attribute customizes UI labels when using scaffolding or data‑binding in ASP.NET MVC/Core.
🔗 Entity Framework Integration
- EF will discover this entity via
DbContext:public class ImagingContext : DbContext { public DbSet<OperatingSystem> OperatingSystems { get; set; } // ... } - Migrations
dotnet ef migrations add AddOperatingSystemTable dotnet ef database update
📊 UML Class Diagram
+----------------------------------+
| OperatingSystem |
+----------------------------------+
| - Id: Int32 [PK] |
| - Name: String |
| - IsAvailableOption: Boolean |
+----------------------------------+
| <<Table("OperatingSystem","irby")>> |
+----------------------------------+
🛠 Sample Usage & Code Snippets
6.1 Inserting Records
using (var context = new ImagingContext())
{
var os = new OperatingSystem
{
Name = "Windows 11",
IsAvailableOption = true
};
context.OperatingSystems.Add(os);
context.SaveChanges();
}
6.2 Querying Available Options
using (var context = new ImagingContext())
{
var availableOS = context.OperatingSystems
.Where(o => o.IsAvailableOption)
.OrderBy(o => o.Name)
.ToList();
foreach (var os in availableOS)
{
Console.WriteLine($"{os.Id}: {os.Name}");
}
}
6.3 Using in ASP.NET Core Drop‑down
// In your Controller
public async Task<IActionResult> Create()
{
ViewData["OperatingSystems"] = new SelectList(
await _context.OperatingSystems
.Where(o => o.IsAvailableOption)
.ToListAsync(),
"Id",
"Name"
);
return View();
}
// In your Razor View
@model YourViewModel
@Html.DropDownListFor(
m => m.SelectedOperatingSystemId,
(SelectList)ViewData["OperatingSystems"],
"Select OS...",
new { @class = "form-control" }
)
🔑 Key Functional Areas
- Domain Modeling
Encapsulates the concept of an operating system in the imaging domain. - Data Validation & Display
Simple UI hint via[Display]. Easily extendable with[Required],[MaxLength], etc. - Schema Mapping
Clear EF mapping ensures correct schema/table resolution.
✅ Conclusion & Best Practices
The OperatingSystem class is a straightforward, single‑purpose entity:
- Lightweight POCO: No business logic; purely data representation.
- Extendable: You can easily add new properties (e.g.,
Version,ReleaseDate) and annotations. - Integration‑Ready: Works seamlessly with EF migrations and ASP.NET Core scaffolding.
💡 Tip: Consider adding data‑annotation attributes like
[Required]or[StringLength(100)]onNameto enforce data integrity both at the database and UI levels.
Happy coding! 🚀