Models

Data Model is a collection of classes wherein you will be working with data and business logic. Hence, basically models are business domain-specific containers. It is used to interact with database. It can also be used to manipulate the data to implement the business logic.

To create a micron model, Just extend IMicron Interface. This helps micron model generator to find create then models.

To link a model to a table, Use [Table("TableName")] class attribute,

Micron models must have Primary key property. To define the primary key just add property attribute [Primary].

Primary Key

In the relational model of databases, a primary key is a specific choice of a minimal set of attributes that uniquely specify a tuple in a relation. Informally, a primary key is "which attributes identify a record".

Example Model:

using Micron;
using System;
using System.Collections.Generic;

namespace Data.Models
{
   /***CUSTOMER MODEL***/
  [Table("customers")]
 public partial class Customer : IMicron
 {
        [Primary]
        public Int32 CustomerID {get; set;}  //Primary key for customer object model
        public String CustomerName {get; set;}
        public String ContactName {get; set;}
        public String Address {get; set;}
        public String City {get; set;}
        public String PostalCode {get; set;}
        public String Country {get; set;}
 }
}

Relationships

A relationship, in the context of databases, is a situation that exists between two relational database tables when one table has a foreign key that references the primary key of the other table.

To define relationships in micron, use the [Foreign(typeof(Product))] property attribute. It is added to the Foreign key property.

A foreign key is a column or group of columns in a relational database table that provides a link between data in two tables. It acts as a cross-reference between tables because it references the primary key of another table, thereby establishing a link between them.

Example:

Order:

using Micron;
using System;
using System.Collections.Generic;

namespace Data.Models
{
  /***ORDER MODEL***/
  [Table("orders")]
 public partial class Order : IMicron
 {
        [Primary]
        public Int32 OrderID {get; set;}
        [Foreign(typeof(Customer))] 
        public Int32 CustomerID {get; set;} //Foreign key to Customer object model
        [Foreign(typeof(Employee))]
        public Int32 EmployeeID {get; set;} 
        public String OrderDate {get; set;} //Foreign key to employee object model
        [Foreign(typeof(Shipper))] 
        public Int32 ShipperID {get; set;}  //Foreign key to shipper object model
 }
}

Order Details

using Micron;
using System;
using System.Collections.Generic;

namespace Data.Models
{
/***ORDER_DETAIL MODEL***/
  [Table("order_details")]
 public partial class Order_Detail : IMicron
 {
        [Primary]
        public Int32 ID {get; set;}
        [Foreign(typeof(Order))]
        public Int32 OrderID {get; set;}
        [Foreign(typeof(Product))]
        public Int32 ProductID {get; set;}
        public Int32 Quantity {get; set;}
 }
}

Employees Model

using Micron;
using System;
using System.Collections.Generic;

namespace Data.Models
{
   /***EMPLOYEE MODEL***/
  [Table("employees")]
 public partial class Employee : IMicron
 {
        [Primary]
        public Int32 ID {get; set;}
        public String LastName {get; set;}
        public String FirstName {get; set;}
        public String BirthDate {get; set;}
        public String Photo {get; set;}
        public String Notes {get; set;}
 }
}

Shippers Model

using Micron;
using System;
using System.Collections.Generic;

namespace Data.Models
{
  /***SHIPPER MODEL***/
  [Table("shippers")]
 public partial class Shipper : IMicron
 {
        [Primary]
        public Int32 ID {get; set;}
        public String ShipperName {get; set;}
        public String Phone {get; set;}
 }
}

Last updated