How to get parent entity property in child entity with foreign key relation in code first?

Mujassir Nasir

I have following two entities Doctor(parent) and DoctorPayment(child)

  1. one possible way is to take Doctor object in DoctorPayment entity and get through Doctor.Name

  2. But I only need DoctorName not whole object in DoctorPayment that should be mapped by DoctorId

I have mentioned just few properties of Doctor entity but it have around 50 properties so I don't want to take Doctor object in DoctorPayment

public class Doctor
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Designation { get; set; }
        public int ModifiedBy { get; set; }
    }

    public class DoctorPayment
    {
        public int Id { get; set; }
        public int DoctorId { get; set; }
        public decimal Amount { get; set; }
        public DateTime Date { get; set; }
        public int ModifiedBy { get; set; }
        public Doctor Doctor { get; set; }      // a possible way to take Doctor object
    }
Kashif Hanif

This is Currently not Possible with Entity Framework.EF does Support Object Mapping Only.You can't Map Single Column using EF.

Only Posssible way is to Get Maping for Whole object i.e Doctor and then you can use EF select to get Name only i.e

var DoctorName=DoctorPayment.Doctor.Name

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get parent entity property in child entity with foreign key relation in code first?

From Dev

Laravel : Error in creating a relation to get first child of each parent entity

From Dev

How to expose Foreign Key property to existing entity having navigational property using EF6 Code First

From Dev

Primary key of Parent Entity not stored as Foreign Key in Child Entity

From Dev

Get foreign key value using Entity Framework code first

From Dev

Entity framework code first, get access to foreign key value

From Dev

How to use a child association property as a Map key in JPA parent entity

From Dev

How to specify a foreign key with code-first Entity Framework

From Dev

How can I add an item to a child entity with foreign key reference to the parent entity in Android Room?

From Dev

Entity Framework Code First Foreign Key issue

From Dev

Code first foreign key association MVC Entity

From Dev

Entity Framework Code First Foreign Key issue

From Dev

Foreign Key in Code First Entity Framework

From Dev

Entity Framework: Foreign Key in code first

From Dev

Entity framework 6 code first saving collection via foreign key relation

From Dev

Entity framework parent -> child linking and foreign key constrain failed error

From Dev

In Entity Framework code first, to map a navigation property do I also need to map the foreign key column

From Dev

Entity Framework: How to specify the name of Foreign Key column on a self-referencing Parent-Child relationship?

From Dev

Defining multiple Foreign Key for the Same table in Entity Framework Code First

From Dev

Entity Framework Code First Foreign Key adding Index as well

From Dev

Entity Framework 6 Code First Foreign Key Without Corresponding Properties

From Dev

Entity Framework Code First and Firebird - Foreign Key name issue

From Dev

Entity Framework Code first adds unwanted foreign key column

From Dev

Entity Framework - Code first - Data annotations - Unnecessary foreign key columns

From Dev

Multiple Foreign Key for Same table in Entity Framework Code First

From Dev

Entity Framework one to optional foreign key code first fluent mapping

From Dev

Entity framework code first cant create primary and foreign key relationship

From Dev

Entity framework code first, custom foreign key name for inheritance

From Dev

Exchanged Foreign Key on Entity Framework Code First From data base

Related Related

  1. 1

    How to get parent entity property in child entity with foreign key relation in code first?

  2. 2

    Laravel : Error in creating a relation to get first child of each parent entity

  3. 3

    How to expose Foreign Key property to existing entity having navigational property using EF6 Code First

  4. 4

    Primary key of Parent Entity not stored as Foreign Key in Child Entity

  5. 5

    Get foreign key value using Entity Framework code first

  6. 6

    Entity framework code first, get access to foreign key value

  7. 7

    How to use a child association property as a Map key in JPA parent entity

  8. 8

    How to specify a foreign key with code-first Entity Framework

  9. 9

    How can I add an item to a child entity with foreign key reference to the parent entity in Android Room?

  10. 10

    Entity Framework Code First Foreign Key issue

  11. 11

    Code first foreign key association MVC Entity

  12. 12

    Entity Framework Code First Foreign Key issue

  13. 13

    Foreign Key in Code First Entity Framework

  14. 14

    Entity Framework: Foreign Key in code first

  15. 15

    Entity framework 6 code first saving collection via foreign key relation

  16. 16

    Entity framework parent -> child linking and foreign key constrain failed error

  17. 17

    In Entity Framework code first, to map a navigation property do I also need to map the foreign key column

  18. 18

    Entity Framework: How to specify the name of Foreign Key column on a self-referencing Parent-Child relationship?

  19. 19

    Defining multiple Foreign Key for the Same table in Entity Framework Code First

  20. 20

    Entity Framework Code First Foreign Key adding Index as well

  21. 21

    Entity Framework 6 Code First Foreign Key Without Corresponding Properties

  22. 22

    Entity Framework Code First and Firebird - Foreign Key name issue

  23. 23

    Entity Framework Code first adds unwanted foreign key column

  24. 24

    Entity Framework - Code first - Data annotations - Unnecessary foreign key columns

  25. 25

    Multiple Foreign Key for Same table in Entity Framework Code First

  26. 26

    Entity Framework one to optional foreign key code first fluent mapping

  27. 27

    Entity framework code first cant create primary and foreign key relationship

  28. 28

    Entity framework code first, custom foreign key name for inheritance

  29. 29

    Exchanged Foreign Key on Entity Framework Code First From data base

HotTag

Archive