Tier Reverse Mapping Map

Thread is closed for posting
2 posts, 1 answers
  1. Jeff Morris
    Jeff Morris avatar
    7 posts
    Member since:
    Mar 2010

    Posted 09 Apr 2010 Link to this post

    I'm creating an application using the same structure as the Northwind N-Tier Web Demo Application.  In my application i have a cross reference table between a Customer table, and Customer property table.  The cross reference table has a value so instead of using open access to reverse map it to a collection i mapped it using the map functionality so I can have access to the value.  When I use the map functionality I get a dictionary object of <Customer, string>.  I have a couple questions.

    1.  Am I using the map functionality correctly?  I'm new to open access and I am learning as I go.
    2.  In the demo application it has an Assembler class that connects the business objects to the Data Access objects using the code below.

        internal static class OrderAssembler 
        { 
            internal static List<Order> AssembleContracts(IQueryable<DAL.Order> froms) 
            { 
                List<Order> tos = new List<Order>(); 
     
                foreach (DAL.Order from in froms) 
                { 
                    tos.Add(AssembleContract(from)); 
                } 
     
                return tos; 
            } 
     
            internal static List<Order> AssembleContracts(IEnumerable<DAL.Order> froms) 
            { 
                List<Order> tos = new List<Order>(); 
     
                foreach (DAL.Order from in froms) 
                { 
                    tos.Add(AssembleContract(from)); 
                } 
     
                return tos; 
            } 
     
            internal static Order AssembleContract(DAL.Order from) 
            { 
                Order to = new Order(); 
     
                to.OrderID = from.OrderID; 
                to.OrderDate = from.OrderDate; 
                to.RequiredDate = from.RequiredDate; 
                to.ShippedDate = from.ShippedDate; 
                to.Freight = from.Freight; 
                to.ShipName = from.ShipName; 
                to.ShipAddress = from.ShipAddress; 
                to.ShipCity = from.ShipCity; 
                to.ShipRegion = from.ShipRegion; 
                to.ShipPostalCode = from.ShipPostalCode; 
                to.ShipCountry = from.ShipCountry; 
     
                if (from.Shipper != null
                { 
                    to.Shipper = ShipperAssembler.AssembleContract(from.Shipper); 
                } 
     
                if (from.Customer != null
                { 
                    to.CustomerID = from.Customer.CustomerID; 
                } 
     
                if (from.Employee != null
                { 
                    to.EmployeeID = from.Employee.EmployeeID; 
                } 
     
                return to; 
            } 
        } 

    What would the AssembleContracts method need to look like to assemble the dictionary property?  

    3.  Is there a better suggestion for having dynamic property values between customers and customer properties other than what I have done?  Thank you.
  2. Answer
    Serge
    Admin
    Serge avatar
    375 posts

    Posted 12 Apr 2010 Link to this post

    Hello Jeff Morris,

    This being a many to many relationship, the preferred approach is explained in this Knowledge Base article. As to the Assembler class, if you decide to use the dictionary approach, what you need to do is first modify the Business Classes and add the appropriate fields (a Dictionary of <Customer, string> in this case). Then in the AssembleContract method use a foreach statement to copy the key-value pairs to the dictionary of the new class. This is pretty straight forward.

    I do suggest using the approach described in the KB article however. If you need more information do not hesitate to contact us.

    Regards,
    Serge
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top