Example: Flattening a large structure



The actual mapping (printed with the PrintTool)

Event <--------------------------> EventInfo
-----------------------------------------------------------
Activity.Id ---------------------> ActivityId
Activity.Name -------------------> ActivityName
Activity.ParentActivityId -------> ParentActivityId
ArrangingOrganization.OrgId -----> ArrangingOrganizaionId
End <----------------------------> End
EntryInfo.Contact.Email ---------> EntryContactEmail
EntryInfo.Contact.HomePage ------> EntryContactHomePage
EntryInfo.Contact.TelephoneNo1 --> EntryContactPhone
EntryInfo.ContactPersonName -----> EntryContactPersonName
EntryInfo.Description -----------> EntryDescription
EventName <----------------------> EventName
GetLastDeadLine.Date ------------> DeadLine
Level <--------------------------> Level
Location <-----------------------> Location
Organizer.Contact.Email ---------> OrganizerContactEmail
Organizer.Contact.HomePage ------> OrganizerContactHomePage
Organizer.Contact.TelephoneNo1 --> OrganizerContactPhone
Organizer.OrgName ---------------> OrganizerOrgName
Season.Name ---------------------> SeasonName
Start <--------------------------> Start


The classes

internal class EventInfo
{
    public string EventName { get; set; }
    public string Location { get; set; }
    public DateTime? Start { get; set; }
    public DateTime? End { get; set; }
    public string EntryDescription { get; set; }
    public string OrganizerOrgName { get; set; }
    public string ActivityName { get; set; }
    public string EntryContactPersonName { get; set; }
    public string EntryContactPhone { get; set; }
    public string EntryContactEmail { get; set; }
    public string EntryContactHomePage { get; set; }
    public string Level { get; set; }
    public string SeasonName { get; set; }
    public string OrganizerContactPhone { get; set; }
    public string OrganizerContactEmail { get; set; }
    public string OrganizerContactHomePage { get; set; }
    public int ArrangingOrganizaionId { get; set; }
    public int ActivityId { get; set; }
    public int ParentActivityId { get; set; }
    public DateTime? DeadLine { get; set; }
}

internal class Event
{
    public string EventName { get; set; }
    public string Location { get; set; }
    public DateTime? Start { get; set; }
    public DateTime? End { get; set; }
    public string Level { get; set; }
    public EventOrganiser Organizer { get; set; }
    public EntryInfo EntryInfo { get; set; }
    public Activity Activity { get; set; }
    public Season Season { get; set; }
    public OrgElement ArrangingOrganization { get; set; }

    public Deadline GetLastDeadLine()
    {
        return new Deadline {Date = DateTime.Now};
    }
}

internal class EventOrganiser
{
    public Contact Contact { get; set; }
    public String OrgName { get; set; }
}

internal class Contact
{
    public String TelephoneNo1 { get; set; }
    public String Email { get; set; }
    public String HomePage { get; set; }
}

internal class EntryInfo
{
    public String Description { get; set; }
    public String ContactPersonName { get; set; }
    public Contact Contact { get; set; }
}

internal class Activity
{
    public String Name { get; set; }
    public int Id { get; set; }
    public int ParentActivityId { get; set; }
}

internal class Season
{
    public String Name { get; set; }
}

internal class Deadline
{
    public DateTime Date { get; set; }
}

internal class OrgElement
{
    public int OrgId { get; set; }
}

The mapping

private Mapping<Event, EventInfo> SetUpMapper()
{
    var theMapping = new Mapping<Event, EventInfo>();            
    theMapping.Relate(x=>x.Activity.Id , y=>y.ActivityId);
    theMapping.Relate(x => x.Activity.Name, y => y.ActivityName);
    theMapping.Relate(x => x.Activity.ParentActivityId, y => y.ParentActivityId);
    theMapping.Relate(x => x.ArrangingOrganization.OrgId, y => y.ArrangingOrganizaionId);
    theMapping.Relate(x => x.End, y => y.End);
    theMapping.Relate(x => x.EntryInfo.Contact.Email, y => y.EntryContactEmail);
    theMapping.Relate(x => x.EntryInfo.Contact.HomePage, y => y.EntryContactHomePage);
    theMapping.Relate(x => x.EntryInfo.Contact.TelephoneNo1, y => y.EntryContactPhone);
    theMapping.Relate(x => x.EntryInfo.ContactPersonName, y => y.EntryContactPersonName);
    theMapping.Relate(x => x.EntryInfo.Description, y => y.EntryDescription);
    theMapping.Relate(x => x.EventName, y => y.EventName);
    theMapping.Relate(x => x.GetLastDeadLine().Date, y => y.DeadLine);
    theMapping.Relate(x => x.Level, y => y.Level);
    theMapping.Relate(x => x.Location, y => y.Location);
    theMapping.Relate(x => x.Organizer.Contact.Email, y => y.OrganizerContactEmail);
    theMapping.Relate(x => x.Organizer.Contact.HomePage, y => y.OrganizerContactHomePage);
    theMapping.Relate(x => x.Organizer.Contact.TelephoneNo1, y => y.OrganizerContactPhone);
    theMapping.Relate(x => x.Organizer.OrgName, y => y.OrganizerOrgName);
    theMapping.Relate(x => x.Season.Name, y => y.SeasonName);
    theMapping.Relate(x => x.Start, y => y.Start);
    return mapping;
}

You can also map this with explicit nested mappings, here's how: Flattening large structure with explicit nested mappings

Last edited Oct 10, 2009 at 6:21 AM by ToreVestues, version 4

Comments

No comments yet.