Quantcast
Channel: glue Wiki & Documentation Rss Feed
Viewing all articles
Browse latest Browse all 20

Updated Wiki: Flattening a large structure

$
0
0

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

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

internalclass Event
{
    publicstring EventName { get; set; }
    publicstring Location { get; set; }
    public DateTime? Start { get; set; }
    public DateTime? End { get; set; }
    publicstring 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()
    {
        returnnew Deadline {Date = DateTime.Now};
    }
}

internalclass EventOrganiser
{
    public Contact Contact { get; set; }
    public String OrgName { get; set; }
}

internalclass Contact
{
    public String TelephoneNo1 { get; set; }
    public String Email { get; set; }
    public String HomePage { get; set; }
}

internalclass EntryInfo
{
    public String Description { get; set; }
    public String ContactPersonName { get; set; }
    public Contact Contact { get; set; }
}

internalclass Activity
{
    public String Name { get; set; }
    publicint Id { get; set; }
    publicint ParentActivityId { get; set; }
}

internalclass Season
{
    public String Name { get; set; }
}

internalclass Deadline
{
    public DateTime Date { get; set; }
}

internalclass OrgElement
{
    publicint 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

Viewing all articles
Browse latest Browse all 20

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>