TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Donald C
NA
153
3.5k
Using Automapper \ Linq .Include to retrieve specific data
Jul 2 2017 5:54 PM
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<Contact> Contacts =
new
List<Contact>();
Contacts.Add(
new
Contact(
"1"
,
"Bob"
,
"Fender"
,
"101"
));
Contacts.Add(
new
Contact(
"2"
,
"Dave"
,
"Jones"
,
"102"
));
ICollection<Misc> Miscs =
new
List<Misc>();
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()
}
}
}
Reply
Answers (
0
)
DeSerialization for circular reference entities
HttpClient Request using c#