📦 BlobData.cs Documentation
Welcome to the BlobData.cs documentation! This guide provides a deep dive into the BlobData domain class, explaining its purpose, structure, and usage within the IrbyImaging solution.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- View Models & Data Models
- Key Functional Areas
- UML Class Diagram
- Key Properties
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third‑Party Integrations
- Sample Code Blocks & Usage Examples
- Conclusion
1. Overview & Purpose
The BlobData class represents the raw image data (blobs) stored in the database. It is part of the IrbyImaging.DomainClasses namespace and serves as a data model for persisting and retrieving image content by its unique identifier.
- Use Case:
- Store scanned documents or image files in a SQL-backed persistence layer.
- Retrieve the image bytes for display or further processing (OCR, thumbnail generation, etc.).
2. Dependencies & Technologies
| Technology / Library | Purpose |
|---|---|
| .NET (C#) | Language for implementing the domain class. |
| System.ComponentModel.DataAnnotations | Data annotation attributes for EF mapping. |
| System.ComponentModel.DataAnnotations.Schema | Schema and column mapping for Entity Framework. |
| Entity Framework (Code-First) | ORM used to map BlobData to the database table. |
3. View Models & Data Models
- BlobData is a Data Model in the Domain Layer.
- There are no accompanying View Models in this file—this class is concerned purely with persistence.
4. Key Functional Areas
- Entity Mapping
- Decorated with
[Table("BlobData", Schema = "irby")]to map to theirby.BlobDatatable.
- Decorated with
- Primary Key Configuration
BlobDataIdis marked with[Key]and[DatabaseGenerated(DatabaseGeneratedOption.None)]to indicate an externally supplied GUID.
- Binary Storage
ImageContentsholds the binary blob of the image.
- Optional Relationship
TempDocumentDataId(commented-out navigation property) suggests a future link to aTempDocumentDataentity.
5. UML Class Diagram
+---------------------------------+
| BlobData |
+---------------------------------+
| – BlobDataId : Guid |
| – ImageContents : byte[] |
| – TempDocumentDataId : Guid? |
+---------------------------------+
| |
+---------------------------------+
6. Key Properties
| Property | Type | Attributes | Description |
|---|---|---|---|
| BlobDataId | Guid |
[Key][DatabaseGenerated(DatabaseGeneratedOption.None)] |
Unique identifier for the blob (GUID must be supplied by consumer). |
| ImageContents | byte[] |
— | Binary contents of the image. |
| TempDocumentDataId | Guid? |
— (Foreign key commented out; navigation property not currently active) | Optional link to a temporary document record. |
7. Helper Methods & Utilities
Note: This class does not include helper methods or utilities. It serves purely as a data container.
8. Error Handling & Return Types
- Error Handling
- None at the class level.
- Validation or size checks (e.g., blob size) should be implemented in service/business layers above.
- Return Types
- Retrieval operations typically return
BlobDatainstances orbyte[]streams.
- Retrieval operations typically return
9. API Endpoints Overview
This file does not define any HTTP endpoints.
API controllers in the application would accept or returnBlobDatainstances when handling image upload/download operations.
10. Third‑Party Integrations
- Entity Framework for ORM.
- No other direct third‑party dependencies in this class.
11. Sample Code Blocks & Usage Examples
a) Inserting a New BlobData
using IrbyImaging.DomainClasses;
// Create a new blob record
var newBlob = new BlobData
{
BlobDataId = Guid.NewGuid(),
ImageContents = File.ReadAllBytes("C:\\images\\scanned-doc.png")
};
// Using your EF DbContext
dbContext.BlobDatas.Add(newBlob);
dbContext.SaveChanges();
b) Retrieving and Streaming an Image
Guid blobId = /* existing GUID */;
var blob = dbContext.BlobDatas.Find(blobId);
if (blob != null)
{
// Send as a file stream in ASP.NET Core
return File(blob.ImageContents, "image/png");
}
else
{
return NotFound("Blob not found.");
}
12. Conclusion
The BlobData class is a simple yet critical component of the IrbyImaging solution, enabling the storage and retrieval of binary image data in a robust, schema-driven way. By leveraging Entity Framework attributes, it cleanly maps to the irby.BlobData database table, ensuring that images can be managed via GUIDs and byte arrays.
Feel free to extend this class by re‑enabling the commented TempDocumentData navigation property or by adding validation attributes (e.g., [MaxLength]) to suit your business requirements.
Happy Imaging! 📸