Hi Guys,
Im working on an old db.
How do I go about configuring Automapper to retrieve the contacts primary email address into the Person class?
How do I structure the .Include subquery so that it only retrieves the first email address (ordered by isPrimary)?
Any help would be appreciated.
Thanks
- pulic class Contact
- {
- public string AccountId { get; set; }
- public string Fname { get; set; }
- public string LName { get; set; }
- //....other fields
- public string RecordId { get; set; }
- }
- public class Misc
- {
- public string AccountId { get; set; }
- public string Rectype {get; set; }
- public string Suplamental { get; set; }
- public string isPrimary { get; set; }
- //....other fields
- public string RecordId { get; set; }
- }
- public class Person
- {
- public string AccountId { get; set; }
- public string Fname { get; set; }
- public string LName { get; set; }
- public string PrimaryEmail {get; set; }
- public string RecordId { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- ICollection
Contacts = new List (); - Contacts.Add(new Contact("1", "Bob", "Fender", "101"));
- Contacts.Add(new Contact("2", "Dave", "Jones", "102"));
- ICollection
Miscs = new List (); - Miscs.Add(new Misc("1", "E", "[email protected]", "1", "101"))
- Miscs.Add(new Misc("1", "E", "[email protected]", "0", "102"))
- Miscs.Add(new Misc("1", "L", "C:\Docs\Bob.doc", "0", "103"))
- Miscs.Add(new Misc("2", "E", "[email protected]", "1", "104"))
- Miscs.Add(new Misc("2", "W", "www.daveswebsite.com", "0", "105"))
- Miscs.Add(new Misc("2", "L", "C:\Docs\Daves.doc", "0", "106"))
- context.Contacts
- .Include(Misc).Where(m => m.Rectype == 'E').OrderbyDescending(isPrimary).FirstOrDefault()
- }
- }
- }
Replies
Know the answer? Post it — somebody with the same question will find it here.