This is a migrated thread and some comments may be shown as answers.

Tier Reverse Mapping Map

1 Answer 63 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeff Morris
Top achievements
Rank 1
Jeff Morris asked on 09 Apr 2010, 03:42 PM
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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Serge
Telerik team
answered on 12 Apr 2010, 04:28 PM
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.
Tags
General Discussions
Asked by
Jeff Morris
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or