locked
Mapping multiple (two) row into one entity – how to? RRS feed

  • Question

  • Hi,

    is it possible to map two or more rows of a table to one entity?

    The property to chose to map to should depend on some column value.

    Example:

    Table

    ¦ID not PK ¦ Condition ¦ ValueColumn¦

    Entity

    public class SomeEntity {

      [Column("ValueColumn")]

      ValueColumnConditionTrue {get; set;}

      [Column("ValueColumn")]

      ValueColumnConditionFalse {get; set;}

    }

    Thanks.


    Thursday, October 18, 2018 8:27 AM

All replies

  • You need to use a DTO.

    https://www.codeproject.com/Articles/1050468/Data-Transfer-Object-Design-Pattern-in-Csharp

    Thursday, October 18, 2018 9:32 AM
  • Hi Uzivatel 919,

    Maybe LINQ Pivot Extensions is helpful for you. for more information, please refer to:

    https://stackoverflow.com/questions/8082057/how-to-use-pivot-table-with-entity-framework

    Or loop the table records, assign to one entity via related condition.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, October 19, 2018 1:36 AM