π LicenseReport Domain Class Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- 3.1 Entity Configuration
- 3.2 Properties
- UML Class Diagram
- Usage & Integration
- Sample Code Blocks
- 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 thatLicenseReportdoes 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 viaFromSqlRaw().
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! π