• Getting Started
    • Prerequisites
    • Download and Installation
    • Change Log
  • Developer Guide
    • EvenCart Plugins
      • Development Environment Setup
      • Plugin Structure
      • EvenCart MVC
      • Dependency Injection
      • Domain Entities
      • Database Versions
      • Plugin Settings
      • Data Provider Plugin
      • Payment Processing Plugin
      • Shipping Provider Plugin
      • Authentication Provider
      • Widget Plugin
    • EvenCart API
      • Authentication
      • Requests & Responses
      • API EndPoints
    • Caching
  • Designer Guide
    • How to create a theme
    • Extended Tags
      • Layout Tag
      • Widget Tag
      • Json Tag
      • Css Tag
      • Js Tag
      • Bundle Tag
      • Partial Tag
      • Control Tag
      • Route Tag
      • Global Tag
      • Component Tag
    • Extended Filters
    • Global Objects
  • Packaging & Distribution

Domain Entities

A domain entity is a class that represent a single database table. The properties of these classes become the columns in the database for that entity table. The following document will describe how to create domain entities in EvenCart plugin.

Domain entity classes

A domain entity class is a class that inherits the abstract class EvenCart.Core.Data.FoundationEntity exposed by EvenCart. All the domain entities in EvenCart have Id as it's primary key column of type integer. The FoundationEntity class declares an integer property called Id to satisfy this.

A few things that need to be aware of while creating domain entity classes are as follows.

  1. Only the properties which are public and have both getter and setter signature are eligible to be mapped for columns.
  2. The domain entity class should be public and should not be declared abstract. If a class is declared abstract it is not mapped to any database table. However it's concrete sub-classes can be mapped to database tables, provided that they also fulfill the conditions listed here.
  3. The properties that need to be mapped to database columns can only have primitive return types.
  4. If a property contains a complex data type such as class then those properties must be declared virtual. These properties will be excluded from mapping.
  5. Make sure that domain class name doesn't have similar name to that of EvenCart entities. Otherwise the plugin is likely to produce unwanted errors.

Creating a domain entity class

The following example shows how to create a domain entity classes named Book and Page. We recommend that each domain entity class should be kept in a separate file with same name.

//Data\Book.cs
@using EvenCart.Core.Data;
public class Book : FoundationEntity
{
    public string Title {get; set;}
    public string Isbn {get; set;}
    public string Author {get;set;} 
}

//Data\Page.cs
public class Page : FoundationEntity
{
    public int BookId {get;set;}
    public string PageNumber {get;set;}
    public string Content {get; set;}   
}

Defining relationships between domain classes

In a typical plugin, we'll have multiple domain classes mapping to multiple database tables. And there will always be relationships between those tables.

To define such relationships between domain classes, virtual properties are used.

The following example modifies the above code to define a one-to-many relationship between Book and Page entities.

//Data\Book.cs
@using EvenCart.Core.Data;
using System.Collections.Generic;
public class Book : FoundationEntity
{
    public string Title {get; set;}
    public string Isbn {get; set;}
    public string Author {get;set;} 

    //property defined as virtual so it's not mapped to any database property
    public virtual IList<Page> Pages {get;set;}
}

//Data\Page.cs
public class Page : FoundationEntity
{
    public int BookId {get;set;}
    public string PageNumber {get;set;}
    public string Content {get; set;}

    //property defined as virtual so it's not mapped to any database property
    public virtual Book Book {get;set;}
}

Note - You should only create domain classes for entities that are specific to your plugin.

Next steps

Once your've created your domain classes, you can move on to create database versions.

ON THIS PAGE
  • Domain entity classes
  • Creating a domain entity class
  • Defining relationships between domain classes
  • Next steps

Related Pages

  • Plugin Structure
  • EvenCart MVC
  • Dependency Injection
  • Database Versions
  • Plugin Settings
© 2022 Sojatia Infocrafts Pvt. Ltd. All rights reserved. Powered by onlyDoc.