📚 Documentation: 20250320211658_AddIntuneTable.Designer.cs
Location:
IrbyImaging.DbContext/Migrations/20250320211658_AddIntuneTable.Designer.cs
Generated By: Entity Framework Core 9.0.0
Context: Auto‑generated migration “AddIntuneTable” for theIrbyContextDbContext.
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Migration Structure
- Key Functional Areas
- “Intune” Table Mapping
- Applying & Using the Migration
- Code Snippets & Examples
- Conclusion
1. Overview & Purpose 🚀
This Designer file is part of the EF Core Code‑First Migration named AddIntuneTable. Its job is to capture the model snapshot after the migration has been applied, so EF Core can compare schema changes over time.
- Auto‑Generated: Do not manually modify. Changes here will be overwritten by EF Core tools.
- BuildTargetModel: Contains a fluent API description of every entity, property, relationship and constraint in the context after the migration.
2. Dependencies & Technologies 🔧
| Technology / Package | Version | Purpose |
|---|---|---|
| Microsoft.EntityFrameworkCore | 9.0.0 | Core ORM engine |
| Microsoft.EntityFrameworkCore.Migrations | 9.0.0 | Migration scaffolding |
| Microsoft.EntityFrameworkCore.SqlServer | 9.0.0 | SQL Server provider w/ identity columns |
| .NET 7+ System libraries | — | Runtime & data types |
3. Migration Structure 🏗️
[DbContext(typeof(IrbyContext))]
[Migration("20250320211658_AddIntuneTable")]
partial class AddIntuneTable
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
// … fluent API model definition …
}
}
DbContextAttribute: Binds the migration toIrbyContext.MigrationAttribute: Names the migration and timestamp.BuildTargetModel: Defines the final EF Core model snapshot.
4. Key Functional Areas 🎯
-
Global Conventions
modelBuilder.HasAnnotation("ProductVersion", "9.0.0")UseIdentityColumns()for SQL Server Identity (auto‑increment) support.
-
Entity Definitions
- Each
modelBuilder.Entity("Namespace.DomainClasses.X", b => { ... })block maps a CLR type to a relational table, configures keys, indexes, column types, and relationships.
- Each
-
Relationships & Navigation
HasOne(...).WithMany(...)andHasForeignKey(...)calls configure one‑to‑many, many‑to‑many, and inheritance (TPH).
-
Discriminator / TPH
- Single‑table inheritance for
Assetderivatives (Computer,MobileDevice, etc.), controlled via.HasDiscriminator().HasValue(...).
- Single‑table inheritance for
-
New “Intune” Table
- Added in this migration: see section below.
5. “Intune” Table Mapping 🔍
The core reason for this migration: add a new Intune entity to track Microsoft Intune device metadata.
| Property | Type | Column Type | Notes |
|---|---|---|---|
IntuneId (PK) |
Guid |
uniqueidentifier |
Auto‑generated on add |
AssetId (FK) |
Guid |
uniqueidentifier |
Links to Asset.Id |
AzureADDeviceId |
string |
nvarchar(max) |
Azure AD device GUID |
AzureADRegistered |
string |
nvarchar(max) |
Registration status |
Category |
string |
nvarchar(max) |
Device category (e.g., PC) |
Compliance |
string |
nvarchar(max) |
Compliance state |
ComplianceGracePeriodExpiration |
DateTime |
datetime2 |
Expiration date |
| … (many Intune‑specific fields) … | … | … | … |
WiFiMAC |
string |
nvarchar(max) |
MAC address |
modelBuilder.Entity("IrbyImaging.DomainClasses.Intune", b =>
{
b.Property<Guid>("IntuneId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid>("AssetId")
.HasColumnType("uniqueidentifier");
b.Property<string>("AzureADDeviceId")
.HasColumnType("nvarchar(max)");
// … other fields …
b.HasKey("IntuneId");
b.ToTable("Intune", "irby");
});
Note: No explicit foreign key is configured here—if needed, update the domain model to include navigation to
Asset.
6. Applying & Using the Migration 🛠️
- Add Migration
dotnet ef migrations add AddIntuneTable - Update Database
dotnet ef database update - Verify
- Check
dbo.irby.Intunetable in SQL Server. - Confirm columns and data types match the model.
- Check
7. Code Snippets & Examples 📖
Example: Domain Entity for Intune
Define your Intune domain class in IrbyImaging.DomainClasses project:
public class Intune
{
public Guid IntuneId { get; set; }
public Guid AssetId { get; set; }
public string AzureADDeviceId { get; set; }
// … other properties …
public Asset Asset { get; set; } // Navigation
}
Example: Querying Intune Records
using var context = new IrbyContext();
var nonCompliantDevices = context.Set<Intune>()
.Where(i => i.Compliance == "NonCompliant")
.Include(i => i.Asset)
.ToList();
foreach (var device in nonCompliantDevices)
{
Console.WriteLine($"{device.Asset.SerialNumber} ⇒ {device.Compliance}");
}
8. Conclusion 🎉
- The Designer file is a read‑only snapshot of your model after adding the Intune table.
- It ensures EF Core can compute diffs for future migrations.
- To customize behavior (indexes, FKs, constraints), modify your DomainClasses or override
OnModelCreatinginIrbyContext, then re‑scaffold.
Happy coding and secure device management! 🔒