๐ Documentation: 20221102175711_NewCoulmnForDocumentAttribute.cs
๐ Table of Contents
- Overview & Purpose
- Schema Changes
UpMethod BreakdownDownMethod Breakdown- Entity Diagram (ASCII/UML)
- Dependencies & Technologies
- Usage & Execution
- Sample Code Blocks & Examples
- Conclusion
๐ Overview & Purpose
This migration file was automatically generated by Entity Framework Core to add two new columns to your database schema:
LinkCustomerDataon theDocumentAttributetableCustomerNameon theCustomertable
Its primary goals are:
- ๐ฏ Extend the
DocumentAttributetable with a boolean flag to indicate linkage to customer data - ๐ฏ Allow storing a humanโreadable
CustomerNamein theCustomertable
Filename
IrbyImaging.DbContext/Migrations/20221102175711_NewCoulmnForDocumentAttribute.csNamespace
IrbyImaging.DbContext.Migrations
๐๏ธ Schema Changes
| Table | Column | Type | Nullable | Default | Description |
|---|---|---|---|---|---|
irby.DocumentAttribute |
LinkCustomerData |
bit |
No | false |
Flag to link customer-specific data |
irby.Customer |
CustomerName |
nvarchar(max) |
Yes | NULL |
Full name or display name of the customer |
๐ ๏ธ Up Method Breakdown
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "LinkCustomerData",
schema: "irby",
table: "DocumentAttribute",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "CustomerName",
schema: "irby",
table: "Customer",
type: "nvarchar(max)",
nullable: true);
}
What happens here?
- AddColumn for
LinkCustomerData- Type:
bool(bitin SQL Server) - Schema:
irby - Table:
DocumentAttribute - Constraints: Nonโnullable, default =
false
- Type:
- AddColumn for
CustomerName- Type:
string(nvarchar(max)) - Schema:
irby - Table:
Customer - Constraints: Nullable
- Type:
๐ The Up method is applied when running
dotnet ef database update, moving your schema forward.
๐งน Down Method Breakdown
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "LinkCustomerData",
schema: "irby",
table: "DocumentAttribute");
migrationBuilder.DropColumn(
name: "CustomerName",
schema: "irby",
table: "Customer");
}
Reverts the changes made in Up:
- Drops the
LinkCustomerDatacolumn - Drops the
CustomerNamecolumn
๐ The Down method is applied when rolling back this migration (e.g.,
dotnet ef database update 20221102175710_PreviousMigration).
๐ผ๏ธ Entity Diagram (ASCII/UML)
+---------------------+ +----------------------+
| DocumentAttribute | | Customer |
|---------------------| |----------------------|
| * Id (PK) | | * Id (PK) |
| * Name | | * Email |
| * Value | | * CreatedAt |
| + LinkCustomerData |โโโโโโ| |
+---------------------+ | + CustomerName |
+----------------------+
- Link from
DocumentAttributetoCustomeris logical; the boolean indicates if additional customer data is required.
โ๏ธ Dependencies & Technologies
- .NET 6.0+, C#
- Entity Framework Core (>= 5.0)
- SQL Server (via
Microsoft.EntityFrameworkCore.SqlServer) - Migrations powered by
Microsoft.EntityFrameworkCore.Tools
๐ Usage & Execution
- Add the Migration (already done):
dotnet ef migrations add NewCoulmnForDocumentAttribute - Apply to Database:
dotnet ef database update - Verify schema changes (e.g., SQL Server Management Studio):
SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'irby' AND TABLE_NAME IN ('DocumentAttribute','Customer');
๐ป Sample Code Blocks & Examples
1. Querying with the New Columns
using (var ctx = new IrbyContext())
{
// Create a new document attribute and link customer data
var docAttr = new DocumentAttribute {
Name = "Requires Verification",
Value = "Yes",
LinkCustomerData = true // ๐ฅ new property
};
ctx.DocumentAttributes.Add(docAttr);
// Create a new customer with CustomerName
var cust = new Customer {
Email = "[email protected]",
CustomerName = "Alice Johnson" // ๐ฅ new property
};
ctx.Customers.Add(cust);
ctx.SaveChanges();
}
2. LINQ Filter Example
// Fetch only attributes linked to customer data
var linkedAttributes = ctx.DocumentAttributes
.Where(a => a.LinkCustomerData)
.ToList();
๐ Conclusion
- Purpose Achieved: Two new columns enrich your data modelโone to flag linkage, another to store a display name.
- Reversible: The migration is fully reversible via the
Downmethod. - Next Steps:
- Update application code to surface
LinkCustomerDataandCustomerNamein your UI or API. - Add validation or business logic where needed (e.g., if
LinkCustomerDataistrue, ensureCustomerNameis populated).
- Update application code to surface
โจ With this migration in place, your domain model is now more expressive and capable of capturing customerโspecific behaviors directly in the database schema.
Generated with โค๏ธ by IrbyImaging EF Core Migrations