π¦ AssetModel.cs Documentation
Welcome to the comprehensive documentation for AssetModel.cs, part of the IrbyImaging.DomainClasses assembly. This document will guide you through the purpose, structure, usage, and relationships of the AssetModel and AssetModelDetail classes, complete with examples, tables, and a UML diagram.
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models
- Properties & Annotations
- Relationships & Navigation
- UML Class Diagram
- Usage Examples
- Sample Code Snippets
- Conclusion
π― Overview & Purpose
The AssetModel.cs file defines two core domain entities used in the Irby Imaging system:
- AssetModel
Represents a template or blueprint for imaging assets (e.g., cameras, scanners) manufactured by a company. - AssetModelDetail
Additional detail records associated with an asset model, used for extended configuration or versioning.
These classes are designed to work with Entity Framework Core, enabling database mapping, queries, and CRUD operations in a clean, maintainable way.
βοΈ Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| .NET Core / .NET Framework | Overall runtime |
| Entity Framework Core (EF Core) | Objectβrelational mapping (ORM) |
| System.ComponentModel.DataAnnotations | Validation & data-model annotations |
| System.ComponentModel.DataAnnotations.Schema | Table mapping |
| IrbyImaging.Utility | Shared utility types/enums (e.g. DeviceType) |
π Key Functional Areas
- ORM Mapping:
[Table],[Key], and navigation properties for EF Core. - Data Validation & Display:
[Display]attributes for UI hints. - Domain Modeling: Clean representation of asset manufacturer, type, category, and details.
- Extension Points: Collection of
AssetModelDetailfor further customization.
π Data Models
AssetModel
[Table("AssetModel", Schema = "irby")]
public class AssetModel
{
[Key]
public int Id { get; set; }
public int MakeId { get; set; }
public Manufacturer Make { get; set; }
public string Name { get; set; }
public AssetCategory Category { get; set; }
public DeviceType? Type { get; set; }
[Display(Name = "Available?")]
public bool IsAvailableOption { get; set; }
public List<AssetModelDetail> AssetsModelDetail { get; set; }
}
Property Summary
| Property | Type | Description |
|---|---|---|
| Id | int |
Primary key identifier |
| MakeId | int |
Foreign key to Manufacturer |
| Make | Manufacturer |
Navigation property to the manufacturer entity |
| Name | string |
Human-readable model name |
| Category | AssetCategory |
Asset categorization (enum) |
| Type | DeviceType? |
Optional device type (enum) |
| IsAvailableOption | bool |
Flag indicating availability in UI forms |
| AssetsModelDetail | List<AssetModelDetail> |
Child details β versions, configurations, etc. |
AssetModelDetail
public class AssetModelDetail
{
public int Id { get; set; }
public int MakeId { get; set; }
public Manufacturer Make { get; set; }
public string Name { get; set; }
public AssetCategory Category { get; set; }
public DeviceType? Type { get; set; }
public bool IsAvailableOption { get; set; }
}
Note: Although
AssetModelDetailshares many fields withAssetModel, it is typically used for finer-grained records (e.g., version-specific details).
π Relationships & Navigation
- AssetModel β Manufacturer
One-to-many: eachAssetModelreferences a singleManufacturerviaMakeId. - AssetModel β AssetModelDetail
One-to-many: eachAssetModelcan have multipleAssetModelDetailentries. - Enumerations
AssetCategory: Grouping of assets (e.g., Hardware, Software).DeviceType: Specific device classification (e.g., Scanner, Printer).
πΌοΈ UML Class Diagram
classDiagram
direction LR
class AssetModel {
+int Id
+int MakeId
+string Name
+AssetCategory Category
+DeviceType? Type
+bool IsAvailableOption
+List~AssetModelDetail~ AssetsModelDetail
}
class AssetModelDetail {
+int Id
+int MakeId
+string Name
+AssetCategory Category
+DeviceType? Type
+bool IsAvailableOption
}
class Manufacturer
class AssetCategory
class DeviceType
AssetModel "1" --> "1" Manufacturer : Make
AssetModel "1" --> "*" AssetModelDetail : AssetsModelDetail
AssetModelDetail "1" --> "1" Manufacturer : Make
π‘ Usage Examples
1. Adding a New AssetModel
using (var context = new IrbyDbContext())
{
var manufacturer = context.Manufacturers.First(m => m.Id == 1);
var newModel = new AssetModel
{
Make = manufacturer,
Name = "X2000 Scanner Pro",
Category = AssetCategory.Hardware,
Type = DeviceType.Scanner,
IsAvailableOption = true,
AssetsModelDetail = new List<AssetModelDetail>
{
new AssetModelDetail
{
Make = manufacturer,
Name = "X2000 Scanner Pro - V2",
Category = AssetCategory.Hardware,
Type = DeviceType.Scanner,
IsAvailableOption = false
}
}
};
context.AssetModels.Add(newModel);
context.SaveChanges();
}
2. Querying AssetModels with Details
var modelsWithDetails = context.AssetModels
.Include(am => am.Make)
.Include(am => am.AssetsModelDetail)
.Where(am => am.IsAvailableOption)
.ToList();
foreach (var model in modelsWithDetails)
{
Console.WriteLine($"{model.Name} by {model.Make.Name}");
foreach (var detail in model.AssetsModelDetail)
{
Console.WriteLine($" - Detail: {detail.Name}, Available: {detail.IsAvailableOption}");
}
}
π οΈ Sample Code Snippets
LINQ Filtering by Category
var hardwareModels = context.AssetModels
.Where(m => m.Category == AssetCategory.Hardware)
.ToList();
Toggling Availability
var asset = context.AssetModels.Find(5);
asset.IsAvailableOption = !asset.IsAvailableOption;
context.SaveChanges();
β Conclusion
The AssetModel and AssetModelDetail classes form the backbone of the Irby Imaging domain for modeling and persisting asset templates and their extended details. With clear ORM mappings, rich navigation properties, and straightforward usage patterns, these classes help you manage your asset catalog efficiently.
Happy coding! π