Note that there are some explanatory texts on larger screens.

plurals
  1. POLinq to SQL and Auto Mapper
    text
    copied!<p>I have the following set up</p> <ul> <li>Linq to SQL data context</li> <li>Data transfer objects (DTO's) that I use to pass data from my business layer to my UI.</li> </ul> <p>The typical use of my DTO is to where I join tables from my database so that I can pass to my UI one data object containing the joined result.</p> <p>I have code similar to this (this is significantly reduced from the real code for posting in SO)...</p> <pre><code>IQueryable&lt;CustomerEventDto&gt; query = ( from ce in db.CustomerEvents join cet in db.CustomerEventTypes on ce.CustomerEventTypeId equals cet.CustomerEventTypeId join c in db.Customers on ce.PidCreating equals c.Pid join c in db.Countries on ce.CountryId equals c.CountryId join t in db.TimeZones on ce.TimeZoneId equals t.TimeZoneId where ce.Pid == pid select new CustomerEventDto() { ApprovedHR = ce.ApprovedHR, City = ce.City, Closed = ce.Closed, CountryId = ce.CountryId, CountryCode = c.CodeISO3166Alpha2, CreatorForename = c.CustomersUnique.Forename, CreatorSurname = c.CustomersUnique.Surname, CreatorUsername = c.UserName, Email = ce.Email, EventDateTime = ce.DateTime, EventType = ce.CustomerEventTypeId, EventTypeDescription = cet.Detail, LockedOutSecurity = ce.LockedOutSecurity, LockedOutSuspension = ce.LockedOutSuspension, TimeZoneDifference = t.Difference, TimeZoneId = ce.TimeZoneId, TimeZoneName = t.ZoneName }); query = query .OptionalWhere(from, ce =&gt; (ce.EventDateTime &gt;= from.StartOfDayNullable())) .OptionalWhere(to, ce =&gt; (ce.EventDateTime &lt;= to.StartOfDayNullable())) .OptionalWhere(eventType, ce =&gt; (ce.EventType == eventType)); return query.ToList(); </code></pre> <p>Is there a way that I can use Auto Mapper to do this mapping?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload