πŸ“‘ StatePropertyCosts Entity Documentation


πŸ“‹ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. Data Model Definition
  5. Entity Framework Core Integration
  6. Sample Code Blocks & Usage Examples
  7. UML Class Diagram
  8. 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

  1. 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
        }
    }
    
  2. Migrations

    • Add a migration:
      dotnet ef migrations add AddStatePropertyCostsEntity
      
    • Update database:
      dotnet ef database update
      
  3. 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! πŸš€