πŸ“„ LicenseReport Domain Class Documentation


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. UML Class Diagram
  5. Usage & Integration
  6. Sample Code Blocks
  7. Conclusion

1. Overview & Purpose

LicenseReport is a keyless Entity Framework Core (EF Core) domain class that maps to a database view or ad-hoc SQL query rather than a standard table with a primary key. It encapsulates all the fields returned by a license-reporting data source, allowing developers to query license information in a strongly-typed manner.

πŸ“Œ Use Case:

  • Generating compliance reports for professional licenses
  • Displaying license expiry and renewal status in dashboards
  • Auditing licensing data across multiple states and issuing bodies

2. Dependencies & Technologies

Component Purpose
Microsoft.EntityFrameworkCore ORM framework for mapping .NET classes to the DB
System.Collections.Generic Collections support (e.g., List<T>)
System.Linq LINQ queries
System.Threading.Tasks Async programming support
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

3. Key Functional Areas

3.1 Entity Configuration

  • [Keyless]
    This attribute denotes that LicenseReport does not have a primary key. EF Core treats it as a query type or view model.
[Keyless]
public class LicenseReport
{
    // ...
}

3.2 Properties

Property Name Type Description
State string Two-letter state code (e.g., β€œCA”, β€œNY”).
LicenseNumber string Unique identifier assigned by the issuing authority.
LicenseClassifications string Human-readable categorization (e.g., β€œGeneral Contractor”).
ClassificationCodes string System or regulatory codes associated with the classification.
IssuingParty string Name of the agency or organization that issued the license.
DateAcquired string Date when the license was first obtained/formatted as string (e.g., β€œ2020-01-15”).
Status string Current license status (e.g., β€œActive”, β€œSuspended”, β€œExpired”).
ExpirationDate string Date when the license will expire.
RenewalStatus string Renewal flag or remark (e.g., β€œRenewed”, β€œPending”).
Qualifiers string Additional notes or qualifiers (e.g., β€œBonded”, β€œInsured”).

4. UML Class Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         LicenseReport           β”‚
β”‚----------------------------------β”‚
β”‚ Β«KeylessΒ»                        β”‚
β”‚----------------------------------β”‚
β”‚ + State: string                  β”‚
β”‚ + LicenseNumber: string          β”‚
β”‚ + LicenseClassifications: string β”‚
β”‚ + ClassificationCodes: string    β”‚
β”‚ + IssuingParty: string           β”‚
β”‚ + DateAcquired: string           β”‚
β”‚ + Status: string                 β”‚
β”‚ + ExpirationDate: string         β”‚
β”‚ + RenewalStatus: string          β”‚
β”‚ + Qualifiers: string             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5. Usage & Integration

5.1 DbContext Configuration

To use LicenseReport in your EF Core DbContext, register it as a keyless entity. Optionally, map it to an actual database view:

public class AppDbContext : DbContext
{
    public DbSet<LicenseReport> LicenseReports { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        // Declare as a keyless entity
        modelBuilder.Entity<LicenseReport>()
            .HasNoKey()
            .ToView("vw_LicenseReport");  // optional: map to a view
    }
}

βš™οΈ Note:

  • If you don’t have a physical view, EF Core still allows ad-hoc queries against tables or inline SQL.
  • Omit .ToView(...) if you plan to query via FromSqlRaw().

5.2 Querying the LicenseReport

Once configured, you can query LicenseReport just like any other DbSet:

// Retrieve all active licenses
var activeLicenses = await context.LicenseReports
    .Where(lr => lr.Status == "Active")
    .ToListAsync();
    
// Filter by state and upcoming expiration
var expiringSoon = await context.LicenseReports
    .Where(lr => lr.State == "CA" && 
                 DateTime.Parse(lr.ExpirationDate) < DateTime.Now.AddMonths(1))
    .ToListAsync();

6. Sample Code Blocks

6.1 Async Retrieval

public async Task<IEnumerable<LicenseReport>> GetExpiredLicensesAsync(AppDbContext context)
{
    return await context.LicenseReports
        .Where(lr => lr.Status == "Expired")
        .OrderBy(lr => DateTime.Parse(lr.ExpirationDate))
        .ToListAsync();
}

6.2 Raw SQL Query

var sql = @"
    SELECT State, LicenseNumber, LicenseClassifications, ClassificationCodes,
           IssuingParty, DateAcquired, Status, ExpirationDate, RenewalStatus, Qualifiers
    FROM LicenseReportTable
    WHERE Status = @status";

var expired = context.LicenseReports
    .FromSqlRaw(sql, new SqlParameter("@status", "Expired"))
    .ToList();

7. Conclusion

LicenseReport is a lightweight, keyless EF Core domain class designed to encapsulate license-reporting data. By leveraging EF Core’s Keyless Entity Types, you can seamlessly integrate complex reporting views or ad-hoc SQL queries into your data layer, providing:

  • βœ… A strongly-typed model for license data
  • βœ… Easy integration into LINQ queries and async workflows
  • βœ… Flexibility to map to database views or raw SQL

With clear property definitions and EF Core support, LicenseReport streamlines the retrieval and presentation of licensing information across your application’s reporting and auditing modules.


Happy Coding! πŸš€