📄 LeasePropertyDetails Data Model Documentation

File: IrbyImaging.DomainClasses/LeasePropertyDetails.cs
Namespace: IrbyImaging.DomainClasses
ORM: Entity Framework Core (Code‑First)


📑 Table of Contents

  1. 📖 Overview & Purpose
  2. 🔑 Key Functional Areas
  3. 🔗 Dependencies & Technologies
  4. 🗃️ Data Model Definition
  5. 🔨 Integrating with EF Core
  6. 🛠️ UML Class Diagram
  7. 💡 Sample Usage & Code Snippets
  8. 🤔 FAQs & Best Practices
  9. 📦 Conclusion

📖 Overview & Purpose

The LeasePropertyDetails class represents the detailed financial and quantitative attributes of leased properties in the Irby Imaging domain. It is designed for use in a Code-First approach with Entity Framework Core, serializing to the irby.LeasePropertyDetails table in the database.

Primary goals:

  • Store lease-related costs and counts.
  • Provide a strongly typed entity for LINQ queries and migrations.
  • Maintain data integrity via Data Annotations.

🔑 Key Functional Areas

  • Entity Definition
    Defines the shape of the LeasePropertyDetails table.
  • Data Annotations
    Configures primary key, schema, and table name.
  • Nullable Value Types
    Enables partial data (e.g., missing insurance payment).

🔗 Dependencies & Technologies

Technology / Package Version or Reference Purpose
Microsoft.EntityFrameworkCore ≥ 5.x ORM for mapping C# classes to database
System.ComponentModel.DataAnnotations Built‑in (.NET Standard) Declarative validation and schema config
System.ComponentModel.DataAnnotations.Schema Built‑in (.NET Standard) Table and column mapping attributes

🗃️ Data Model Definition

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace IrbyImaging.DomainClasses
{
    [Table("LeasePropertyDetails", Schema = "irby")]
    public class LeasePropertyDetails
    {
        [Key]
        public Guid Id { get; set; }

        public string LeasePurpose { get; set; }

        public int? NumberOfProperties { get; set; }

        public decimal? MonthlyAVTax { get; set; }

        public decimal? MonthlyBaseRent { get; set; }

        public decimal? MonthlyInsurancePayment { get; set; }

        public decimal? MonthlySalesTax { get; set; }

        public decimal? MonthlyTotalCost { get; set; }
    }
}

🔍 Property Reference

Property Name Type Nullable Description
Id Guid No Primary key, unique identifier.
LeasePurpose string Yes Purpose or description of the lease (e.g., “Office Use”).
NumberOfProperties int? Yes Count of leased properties.
MonthlyAVTax decimal? Yes Assessed value tax portion per month.
MonthlyBaseRent decimal? Yes Base rent amount per month.
MonthlyInsurancePayment decimal? Yes Monthly insurance payment.
MonthlySalesTax decimal? Yes Sales tax component per month.
MonthlyTotalCost decimal? Yes Aggregate cost (rent + taxes + insurance).

🔨 Integrating with EF Core

  1. Include in your DbContext:

    public class IrbyDbContext : DbContext
    {
        public IrbyDbContext(DbContextOptions<IrbyDbContext> options)
            : base(options) { }
    
        public DbSet<LeasePropertyDetails> LeasePropertyDetails { get; set; }
    
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Fluent configurations (if needed)
            modelBuilder.Entity<LeasePropertyDetails>()
                .Property(l => l.MonthlyTotalCost)
                .HasColumnType("decimal(18,2)");
        }
    }
    
  2. Register in Dependency Injection (ASP.NET Core):

    services.AddDbContext<IrbyDbContext>(options =>
        options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
    
  3. Perform Migrations:

    dotnet ef migrations add AddLeasePropertyDetailsTable
    dotnet ef database update
    

🛠️ UML Class Diagram

classDiagram
    class LeasePropertyDetails {
      <<Entity>>
      +Guid Id
      +string LeasePurpose
      +int? NumberOfProperties
      +decimal? MonthlyAVTax
      +decimal? MonthlyBaseRent
      +decimal? MonthlyInsurancePayment
      +decimal? MonthlySalesTax
      +decimal? MonthlyTotalCost
    }

Legend:
• + Public member
• ? Nullable


💡 Sample Usage & Code Snippets

1. Creating a New Record

var leaseDetails = new LeasePropertyDetails
{
    Id = Guid.NewGuid(),
    LeasePurpose = "Laboratory Equipment",
    NumberOfProperties = 2,
    MonthlyBaseRent = 1500.00m,
    MonthlyAVTax = 75.50m,
    MonthlyInsurancePayment = 125.00m,
    MonthlySalesTax = 30.00m,
};

// Save to database
using var context = serviceProvider.GetRequiredService<IrbyDbContext>();
context.LeasePropertyDetails.Add(leaseDetails);
await context.SaveChangesAsync();

2. Querying Records

var result = await context.LeasePropertyDetails
    .Where(l => l.MonthlyTotalCost > 1000)
    .ToListAsync();

3. Calculating Total Cost (in-memory)

If you wish to auto‑calculate MonthlyTotalCost:

leaseDetails.MonthlyTotalCost =
    (leaseDetails.MonthlyAVTax ?? 0)
  + (leaseDetails.MonthlyBaseRent ?? 0)
  + (leaseDetails.MonthlyInsurancePayment ?? 0)
  + (leaseDetails.MonthlySalesTax ?? 0);

🤔 FAQs & Best Practices

  • Q: Why are most fields nullable?
    A: To allow partial entry of leasing details when not all costs are known upfront.

  • Q: Should I calculate MonthlyTotalCost in code or database?
    A: For reporting-heavy scenarios, consider a computed column in SQL. Otherwise, compute it in service/business layer.

  • Q: How to extend this entity?
    A: Use EF Core’s Fluent API in OnModelCreating or add DataAnnotations for new properties.


📦 Conclusion

The LeasePropertyDetails class is a lean, EF Core-mappable entity tailored for capturing per‑month financial details of leased properties within the Irby Imaging system. By combining Data Annotations with Code‑First migrations, you gain full control over your schema while keeping business logic strongly typed and maintainable.

Happy coding! 🚀