Introduction
SupermarketWEB uses Entity Framework Core with a set of interconnected data models that represent the core business entities. The application manages products, categories, customers, payment modes, and users through a centralized database context.Database Context
TheSupermarketContext class inherits from DbContext and provides access to all entity sets in the application:
Entity Relationships
The data models form a structured hierarchy with the following relationships:Product-Category
Many-to-One relationship. Each Product belongs to one Category, and each Category can have multiple Products.
Independent Entities
Customer, PayMode, and User entities operate independently without direct foreign key relationships to other models.
Product-Category Relationship
The primary relationship in the system is between Product and Category:- Product contains a
CategoryIdforeign key and aCategorynavigation property - Category contains a
Productscollection navigation property - This establishes a one-to-many relationship where one category can contain multiple products
Core Models
Product
Product inventory with pricing, stock levels, and category classification
Category
Product categorization with hierarchical organization
Customer
Customer information including personal details and contact information
PayMode
Payment method definitions for transaction processing
User
Authentication and user account management
Navigation Properties
Navigation properties enable Entity Framework to load related data:Navigation properties marked with
? (nullable) indicate optional relationships that may be lazy-loaded or explicitly included in queries.Data Annotations
The models use data annotations for:- Column Type Specifications:
[Column(TypeName = "decimal(6,2)")]for precise decimal handling - Validation:
[Required]for mandatory fields - Data Type Hints:
[DataType(DataType.EmailAddress)]and[DataType(DataType.Password)]for UI rendering
Data annotations provide both database schema configuration and client-side validation rules.
Entity States
All models follow standard Entity Framework entity states:| State | Description |
|---|---|
| Added | New entity to be inserted |
| Modified | Existing entity with changes |
| Deleted | Entity marked for deletion |
| Unchanged | Tracked entity with no changes |
| Detached | Entity not tracked by context |
Next Steps
Explore individual model documentation for detailed property definitions, validation rules, and usage examples:- Product Model - Inventory and pricing
- Category Model - Product classification
- Customer Model - Customer management
- PayMode Model - Payment methods
- User Model - Authentication