π Documentation: 20230614163408_AddBlobNameColumn.Designer.cs
File Path:
IrbyImaging.DbContext/Migrations/20230614163408_AddBlobNameColumn.Designer.cs
π Table of Contents
- Overview & Purpose
- Migration Context
- BuildTargetModel Method
- Entity Configurations
4.1 Asset & Inheritance Hierarchy
4.2 DocumentImage & BlobName Column
4.3 Other Major Entities (Summary) - Relationships & Navigation Properties
- Indexes & Constraints
- UML Diagram
- Dependencies & Technologies
- Usage Example
- Generating & Applying Migrations
- Conclusion
1. Overview & Purpose
π Purpose
This designer file is auto-generated by Entity Framework Core (EF Core) as part of the AddBlobNameColumn migration (20230614163408). It provides a snapshot of the target database model after the migration is applied.
π What It Does
- Defines the complete EF Core model via the
BuildTargetModel(ModelBuilder modelBuilder)method. - Configures entities, properties, schemas, relationships, indexes, and discriminators.
- Highlights the addition of a new column,
BlobName, to the DocumentImage table.
2. Migration Context
- Migration Name:
20230614163408_AddBlobNameColumn - DbContext:
IrbyContext - EF Core Version:
5.0.12 - Provider: Microsoft SQL Server (
SqlServer:ValueGenerationStrategy = IdentityColumn)
Note: This file is not handβedited. Instead, EF Core scaffolds it when you run
dotnet ef migrations add AddBlobNameColumn
3. BuildTargetModel Method
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 128)
.HasAnnotation("ProductVersion", "5.0.12")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
// ... Entity configurations follow ...
#pragma warning restore 612, 618
}
- Annotations: Set max identifier length, product version, and default value generation strategy.
- Entity Registration: Calls
modelBuilder.Entity(...)for each domain class.
4. Entity Configurations
4.1 Asset & Inheritance Hierarchy ποΈ
EF Core uses Table Splitting and TPT/TPCβstyle mapping with a discriminator column named Discriminator.
| Base Type | Discriminator Value | Derived Type |
|---|---|---|
Asset |
"Asset" |
β (base) |
Asset |
"Computer" |
Computer |
Asset |
"DesktopPhone" |
DeskPhone |
Asset |
"Dock" |
Dock |
Asset |
"MobileDevice" |
MobileDevice |
Asset |
"Monitor" |
Monitor |
Asset |
"NetworkEquipment" |
NetworkEquipment |
Asset |
"OfficePrinter" |
OfficePrinter |
Asset |
"Printer" |
Printer |
Asset |
"SafetyEquipment" |
SafetyEquipment |
Common Asset Properties:
| Property | Type | Required? | Notes |
|---|---|---|---|
Id |
Guid |
β | PK, Identity |
Category |
string |
β | nvarchar(max) |
ModelId |
int |
β | FK β AssetModel |
PurchaseDate |
DateTimeOffset |
β | |
SerialNumber |
string |
β | |
Status |
string |
β | nvarchar(max) |
NeedsReview |
bool |
β | bit |
Notes |
string |
β | nvarchar(max) |
OwnerId |
Guid? |
β | FK β Employee |
FieldOfficeId |
Guid? |
β | FK β FieldOffice |
Derived types add their own specialized properties (e.g., Imei, PhoneNumber for MobileDevice).
4.2 DocumentImage & BlobName Column π¦
This migration introduces the BlobName column to the DocumentImage table (schema: irby).
modelBuilder.Entity("IrbyImaging.DomainClasses.DocumentImage", b =>
{
b.ToTable("DocumentImage", "irby");
// Primary Key
b.Property<Guid>("DocumentImageId")
.HasColumnType("uniqueidentifier")
.ValueGeneratedOnAdd();
// Newly added column:
b.Property<string>("BlobName")
.HasColumnType("nvarchar(max)");
// Other existing properties...
b.Property<string>("FileName")
.HasColumnType("nvarchar(max)");
b.Property<string>("ContentType")
.HasColumnType("nvarchar(max)");
b.Property<byte[]>("ImageContents")
.HasColumnType("varbinary(max)");
b.Property<byte[]>("ImageOCRContents")
.HasColumnType("varbinary(max)");
b.Property<string>("ImageOCRText")
.HasColumnType("nvarchar(max)");
// β¦ (many more)
b.HasKey("DocumentImageId").HasName("PrimaryKey_DocumentImageId");
});
Table: irby.DocumentImage
| Column | Type | Notes |
|---|---|---|
DocumentImageId |
uniqueidentifier |
PK |
BlobName |
nvarchar(max) |
New |
FileName |
nvarchar(max) |
|
ContentType |
nvarchar(max) |
|
ImageContents |
varbinary(max) |
|
ImageOCRContents |
varbinary(max) |
|
ImageOCRText |
nvarchar(max) |
|
| β¦ | β¦ | β¦ |
4.3 Other Major Entities (Summary)
This migration snapshot contains 40+ domain entities. Below are a few highlights; consult the code for the full list:
| Entity | Table | Schema | Comments |
|---|---|---|---|
AssetHistory |
AssetHistory |
irby | Logs changes to assets |
AssetModel |
AssetModel |
irby | Defines makes and models |
CarrierType |
CarrierType |
irby | Lists types of carriers |
CovidTestData |
CovidTestData |
irby | Stores COVID test results & images |
Customer |
Customer |
irby | Customer master data |
DocumentCategory |
DocumentCategory |
irby | Document type categories |
Employee |
Employee |
irby | Company employees |
FieldOffice |
FieldOffice |
irby | Construction site offices |
GeneralLedger |
GeneralLedger |
irby | GL Codes |
Job |
Job |
irby | Project or job records |
ODS_Employee_Staging |
ODS_Employee_Staging |
irby | ERP staging for employees |
ODS_Jobs_Staging |
ODS_Jobs_Staging |
irby | ERP staging for jobs |
Ticket |
Ticket |
irby | Support or service tickets |
Update |
Update |
irby | Ticket updates (FK β Ticket) |
| β¦ | β¦ | β¦ | β¦ |
5. Relationships & Navigation Properties π
- OneβtoβMany:
AssetβAssetHistoryAssetModelβAssetModelDetailFieldOfficeβAssetsEmployeeβAssets,UpdatesTicketβUpdates
- ManyβtoβOne (FKs):
Asset.ModelIdβAssetModel.IdAsset.OwnerIdβEmployee.IdAsset.FieldOfficeIdβFieldOffice.Id
- Unique Index / Alternate Keys:
Employee.JdeNumber(unique)FieldOffice.JdeNumber(unique)Job.JdeNumber(unique)
Navigation properties are defined to facilitate LINQ queries, e.g.,
public class Asset
{
public Guid Id { get; set; }
public AssetModel Model { get; set; }
public Employee Owner { get; set; }
public FieldOffice FieldOffice { get; set; }
public ICollection<AssetHistory> History { get; set; }
}
6. Indexes & Constraints π
| Table | Index / Constraint | Columns | Type |
|---|---|---|---|
Asset |
PK | Id |
Primary |
Asset |
IX_Asset_ModelId | ModelId |
Index |
Employee |
UQ_Employee_JdeNumber | JdeNumber |
Unique |
FieldOffice |
UQ_FieldOffice_JdeNumber | JdeNumber |
Unique |
MobileDevice |
UQ_MobileDevice_Imei | Imei |
Unique |
DocumentImage |
PK_PrimaryKey_DocumentImageId | DocumentImageId |
Primary |
Ticket |
PK | Id |
Primary |
Update |
FK_Update_TicketId (Cascade Delete) | TicketId |
Foreign |
| β¦ | β¦ | β¦ | β¦ |
7. UML Diagram π§©
classDiagram
class Asset {
+Guid Id
+string Category
+int ModelId
+DateTimeOffset PurchaseDate
+string SerialNumber
+bool NeedsReview
+string Status
+string Notes
}
Asset <|-- Computer
Asset <|-- MobileDevice
Asset <|-- DeskPhone
Asset <|-- Monitor
class DocumentImage {
+Guid DocumentImageId
+string BlobName
+string FileName
+string ContentType
+byte[] ImageContents
+byte[] ImageOCRContents
}
class AssetModel {
+int Id
+string Name
}
class Employee {
+Guid Id
+string FirstName
}
AssetModel "1" -- "*" Asset : "Assets"
Employee "1" -- "*" Asset : "Assets"
Asset "*" -- "*" DocumentImage : "References?"
8. Dependencies & Technologies π οΈ
- .NET 5.0
- EntityFrameworkCore 5.0.12
- Microsoft.EntityFrameworkCore.SqlServer
- C# 9.0
- SQL Server (Identity columns, nvarchar(max), varbinary(max), datetimeoffset)
9. Usage Example πββοΈ
Once you have this migration in your project:
# Scaffold the migration (already done)
dotnet ef migrations add AddBlobNameColumn
# Apply to database
dotnet ef database update
In your C# code, you can now reference the new BlobName:
var doc = new DocumentImage {
FileName = "invoice.pdf",
BlobName = "invoices/2023/06/invoice.pdf",
ContentType = "application/pdf",
ImageContents = myByteArray
};
context.DocumentImages.Add(doc);
await context.SaveChangesAsync();
10. Generating & Applying Migrations βοΈ
- Add Column in Domain Model (if you track model):
public class DocumentImage { public Guid DocumentImageId { get; set; } public string BlobName { get; set; } // New property // ... } - Create Migration:
dotnet ef migrations add AddBlobNameColumn - Review Generated Files:
20230614163408_AddBlobNameColumn.cs20230614163408_AddBlobNameColumn.Designer.cs
- Apply to Database:
dotnet ef database update
11. Conclusion π―
This Designer snapshot is crucial for EF Core to understand your target database model. It captures:
- The addition of the
BlobNamecolumn to theDocumentImagetable. - The full entity graph, inheritance hierarchies, navigations, indexes, and schema details.
By maintaining this file alongside your migrations, EF Core can reliably apply, rollback, and scaffold future migrations as your domain model evolves. Happy coding! π