Friday, May 27, 2016

Creating Base and Derived Tables,Table Inheritance in AX 2012

A table also can derive from another table.tables in AX 2012 have two new properties; (1) SupportInheritance property, and (2) the Extends property

one table is  base table, and the other is  derived table
When we use of inheritance between two tables.when all the following conditions are true:

  1. There is no thought that there might be a 1-to-many or many-to-many relationship between the two tables.
  2. An existing row in the proposed base table, and the corresponding row in the derived table, both refer to the same item in the real world.
  3. Each row in the proposed base table has exactly one corresponding row in the derived table.
  4. If one row is ever deleted from either table, the corresponding row must also be deleted.
  5. The base table probably has at least two tables that derive from it.
    1. The two derived tables have fields for different kinds of things.
    2. The two derived tables refer to different variations of the general items that are tracked together in the base table. 
  6. No item that is represented in a base table would ever be represented in more than one of its derived tables.
  7. The derived table is not meant for performance tuning of the physical database, such as placing an image column in its own table.
example of Variations to a Listing:=

Color,Fabric,Flavor,Height,Length,Material,Size,Style,Weight,Width

Example of different Kinds of things
fruit- apples, grapes, and pears
Animals:-amphibians,birds,fish,invertebrates,mammals,reptiles

A T-shirt might come in multiple colors and sizes

ID
Name
Brand
Size
Color
1
T-Shirts
L
Green  
2
T-Shirts
Nike
S
Blue  
3
Adidas
XL
Green  
4
T-Shirts
Lee  
S
White  


Step-1  Create a table called “Tshirt
Step-2  Set table property 'supportInheritance' to 'Yes'
Step-3  Create a filed name called 'InstanceRelationType' extends 'RelationType'
Step-4  Set table property 'InstanceRelationType' to 'InstanceRelationType'
Step-5  Create two filed called Id and Name,Brand as shown below screen



Step-6  Create another table called “Tabtshirtsize”
Step-7  Set table property 'supportInheritance' to 'Yes'
Step-8  Set table property 'Extends' to “Tshirt”

Step-9  Create filed called size as shown below screen


Step-10  Create another table called “Tabtshirtcolor”
Step-11 Set table property 'supportInheritance' to 'Yes'
Step-12  Set table property 'Extends' to “Tshirt”

Step-13 Create filed called size as shown below screen



we need to also set the ‘Abstract’ property of the parent table to ‘Yes’ 

Records can only be created for concrete table types. Any attempt to create a record and insert it in an abstract table will result in a run-time error

Insert Recrod on derived Table

static void dataInsert_tshirt(Args _args)
{

Tabtshirtsize tsize;
  
    tsize.Id=3;
    tsize.Brand="Lee";
    tsize.Name="T-Shirts";
    tsize.Size="S";
    tsize.insert();
    print "insert Record";
    pause;
   

}











No comments:

Post a Comment