Generating tables

2 posts, 1 answers
  1. Christian
    Christian avatar
    81 posts
    Member since:
    Aug 2008

    Posted 12 Jan 2009 Link to this post

    Hi,
    I have the following problem:
    In the data model, there are three classes 'order ','orderitems' and 'product '. Each order has an unlimited number of order positions. Each position item has exactly one entry for a product.
    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Text;  
     
    namespace OrderTest  
        {  
        [Telerik.OpenAccess.Persistent()]  
        public class Order  
            {  
            public Order(){}  
     
            private string ordername;  
            private IList<OrderItem> orderitems;  
     
            public string Ordername  
                {  
                get 
                    {  
                    return this.ordername;  
                    }  
                set 
                    {  
                    this.ordername = value;  
                    }  
                }  
              
            }  
     
        [Telerik.OpenAccess.Persistent()]  
        public class Product  
            {  
            public Product()  
                {  
                }  
     
            private string productname;  
     
            [Telerik.OpenAccess.FieldAlias("productname")]  
            public string Productname  
                {  
                get 
                    {  
                    return this.productname;  
                    }  
                set 
                    {  
                    this.productname = value;  
                    }  
                }  
            }  
     
        [Telerik.OpenAccess.Persistent()]  
        public class OrderItem  
            {  
     
            private Product ordercontent;  
            private int orderposition;  
     
            public OrderItem(){}  
     
            public Product OrderContent  
                {  
                get 
                    {  
                    return this.ordercontent;  
                    }  
                set 
                    {  
                    this.ordercontent = value;  
                    }  
                }  
     
            public int OrderPosition  
                {  
                get 
                    {  
                    return this.orderposition;  
                    }  
                set 
                    {  
                    this.orderposition = value;  
                    }  
                }  
            }  
          
        }  
     


    The order positions for a order will have row number  (orderposition). When creating the classes, the mapper, however, produced four tables: ordr, ordr_order_item, order_item and product.
    My problem is that when you delete a order position in the connection table between order and order the item correctly processed. The table with the order position itself, however, is not changed and therefore contains records that are no longer connected to a record in the order table.
    My question is: How can I make the mapper just the three required to create tables.

    For suggestions, I would be grateful.
    Christian
  2. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 13 Jan 2009 Link to this post

    Hi Christian,

      When having one-to-many relation in your persistent model there are to ways to create the database-schema. The default is by creating a join-table, but if you want to avoid that you have to disable it from the forward mapping wizard. Since the join table is created because of the orderitems field of the Order class, you need to expand the tree node for Order in the forward mapping wizard and select orderitems. The new content of the form contains a group box called "Relationship". It has a checkbox "Join Table" within it and you need to uncheck it so that a join table for Order and Orderitems would not be created or used.

    I hope this will help you achieve the goals planned for your project.

    Best wishes,
    Zoran
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. DevCraft banner
Back to Top