Why Join
Become a member
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
C# Corner Home
Technologies
MonthlyLeaders
ASK A QUESTION
Forumguidelines
Guest User
Tech Writer
62
1.4k
Mappint 2 or more entities into 1 model (Not AutoMapper)
Nov 21 2019 6:52 PM
I have 2 entities which the People and Contact
public
class
People{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public
Guid Id {
get
;
set
; }
public
string
FirstName {
get
;
set
; }
public
string
LastName {
get
;
set
; }
}
public
class
Contact{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public
Guid Id {
get
;
set
; }
public
Guid PeopleId {
get
;
set
; }
public
string
Type {
get
;
set
; }
public
string
ContactNumber {
get
;
set
; }
}
and I have the model ContactModel to display the entity.
public
class
ContactModel{
public
Guid Id {
get
;
set
; }
public
Guid PeopleId {
get
;
set
; }
public
string
FirstName {
get
;
set
; }
public
string
LastName {
get
;
set
; }
public
string
Type {
get
;
set
; }
public
string
ContactNumber {
get
;
set
; }
}
my problem is when I'm trying to map the entities to model, I can only map the People entity or one entity and the the two entities.
public
static
ContactModel ToModel(
this
People people){
return
new
ContactModel{
Id = people.Id,
FirstName = people.FirstName,
LastName = people.LastName
};
}
Reply
Answers (
5
)
How can I give grid view edit permission depends on departme
How to read String Array to Load DataTable in C# ?