Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Answer
Using Automapper \ Linq .Include to retrieve specific data
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Donald C
7y
228
1
Reply
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()
}
}
}
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
DeSerialization for circular reference entities
HttpClient Request using c#