locked
Property mapping in Entity Framework RRS feed

  • Question

  • I was wondering if there is conditional mapping of a property in entity with one or more columns in database table.
    Take this example
    OrderDetail (Table)
    OrderId Int
    LineId int (unique in each order)
    ItemType smallint (1=item, 2=service, 3=Kit)
    ItemKey nvarchar(10) null,
    ServiceKey nvarchar(10) null,
    KitKey nvarchar(10) null,
    ...other fields
    Based on what ItemType is, one of the columns ItemKey, ServiceKey or KitKey is poulated in the database
    Now I want an entity like this
    OrderDetailEntity (Properties as below)
    OrderId As Integer
    ItemType As ItemTypeEnum
    ItemKey as String (here I want to map either itemkey or ServiceKey or KitKey based on ItemType value)
    Is this possible in entity framework?

    Thanks in advance,

    Abhishek

    Wednesday, April 21, 2010 11:15 AM

Answers

  • If you want the exact model that is mentioned, you would have to use DefiningQueries or QueryViews for queries and stored procs for CUD operations instead of the regular mapping.

    You can map these to three different entities though using regular mapping: OrderDetail abstract( Properties: OrderId, LineId), ItemDetail: OrderDetail( Properties: ItemKey, Condition: ItemType = 1), ServiceDetail: OrderDetail( Properties: ServiceKey, Condition: ItemType = 2), ItemDetail: KitDetail( Properties: KitKey, Condition: ItemType = 3).

    Thanks

    Srikanth

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Monday, April 26, 2010 8:49 PM