π StatePropertyCosts Entity Documentation
π Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Data Model Definition
- Entity Framework Core Integration
- Sample Code Blocks & Usage Examples
- UML Class Diagram
- Conclusion
π Overview & Purpose
The StatePropertyCosts class is a Domain Model within the IrbyImaging.DomainClasses namespace.
It represents the monthly cost summary of property-related expenses at the U.S. state level.
-
Why this class exists
- To store and retrieve aggregated cost data by state.
- To serve as a single source of truth for reporting, analytics, and billing scenarios.
-
Primary Responsibilities
- Define the database schema mapping for EF Core.
- Enforce data validation via attributes.
- Provide a strongly-typed object for CRUD operations.
π― Key Functional Areas
- Schema Mapping
- Data Validation
- Identity Tracking
- Aggregation Storage
π Dependencies & Technologies
| Component | Purpose |
|---|---|
Microsoft.EntityFrameworkCore |
ORM for database mapping & querying |
System.ComponentModel.DataAnnotations |
Data annotation attributes for validation |
System.ComponentModel.DataAnnotations.Schema |
Mapping CLR classes to DB tables |
π Data Model Definition
namespace IrbyImaging.DomainClasses
{
[Table("StatePropertyCosts", Schema = "irby")]
public class StatePropertyCosts
{
[Key]
public Guid Id { get; set; }
public string State { get; set; }
public decimal MonthlyTotal { get; set; }
}
}
Class Attributes
| Attribute | Description |
|---|---|
[Table("StatePropertyCosts", Schema = "irby")] |
Maps this class to the irby.StatePropertyCosts table in the database. |
Properties
| Property | Type | Description |
|---|---|---|
| Id | Guid |
π Primary key β uniquely identifies each record. |
| State | string |
π·οΈ Twoβletter postal code or full state name; denotes the U.S. state. |
| MonthlyTotal | decimal |
π° The aggregated cost for the given state for one month (currency value). |
π§© Entity Framework Core Integration
-
DbContext Registration
public class ApplicationDbContext : DbContext { public DbSet<StatePropertyCosts> StatePropertyCosts { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // Optional: Further Fluent API configuration } } -
Migrations
- Add a migration:
dotnet ef migrations add AddStatePropertyCostsEntity - Update database:
dotnet ef database update
- Add a migration:
-
Seeding Example
modelBuilder.Entity<StatePropertyCosts>().HasData( new StatePropertyCosts { Id = Guid.Parse("a1b2c3d4-e5f6-47a8-9012-abcdef345678"), State = "CA", MonthlyTotal = 12500.75M }, new StatePropertyCosts { Id = Guid.NewGuid(), State = "NY", MonthlyTotal = 9800.40M } );
π» Sample Code Blocks & Usage Examples
1. Creating a New Record
using (var context = new ApplicationDbContext())
{
var cost = new StatePropertyCosts
{
Id = Guid.NewGuid(),
State = "TX",
MonthlyTotal = 15000.25M
};
context.StatePropertyCosts.Add(cost);
context.SaveChanges();
}
2. Querying by State
using var context = new ApplicationDbContext();
var texasCost = context.StatePropertyCosts
.FirstOrDefault(s => s.State == "TX");
Console.WriteLine($"TX Monthly Cost: {texasCost?.MonthlyTotal:C}");
3. Updating a Record
using var context = new ApplicationDbContext();
var existing = context.StatePropertyCosts
.SingleOrDefault(s => s.State == "FL");
if (existing != null)
{
existing.MonthlyTotal += 500M;
context.SaveChanges();
}
4. Deleting a Record
using var context = new ApplicationDbContext();
var obsolete = context.StatePropertyCosts.Find(obsoleteId);
if (obsolete != null)
{
context.StatePropertyCosts.Remove(obsolete);
context.SaveChanges();
}
π UML Class Diagram
ββββββββββββββββββββββββββββββ
β StatePropertyCosts β
ββββββββββββββββββββββββββββββ€
β + Id : Guid β
β + State : string β
β + MonthlyTotal : decimal β
ββββββββββββββββββββββββββββββ€
β <<Table("irby.StatePropertyCosts")>> β
β <<Key>> β
ββββββββββββββββββββββββββββββ
β Conclusion
The StatePropertyCosts entity is a lightweight, schema-aligned model designed to capture and persist monthly property cost aggregates by state. Leveraging Entity Framework Core, it provides seamless ORM integration, enabling:
- CRUD operations on state cost records
- Data consistency through GUID-based identity
- Scalability for reporting and analytics modules
By following the patterns and code snippets above, you can easily integrate, seed, and manipulate stateβlevel property cost data in your ASP.NET Core or .NET 6+ application. Feel free to extend the model with additional properties (e.g., Year, TaxAmount) or relationships (e.g., linking to a Property entity) as your business requirements evolve.
Happy coding! π