locked
AddObject SubType with Beta2 RRS feed

  • Question

  • Hi.

     

    Please, how can I add an object that inherits another (TPT) in AddObject regarding that now is need to pass entityset name and I have only base type entityset. I tried pass basetype entityset but it only added the base type. For example, in the NorthwindEF sample, how can I add the InternationalOrder type?

     

    Thanks,

     

    Vítor

    Sunday, September 16, 2007 12:42 AM

Answers

  • Actually, passing the base type entityset is probably exactly what you want to do.  Normally you will have an entityset that contains both instances of the basetype and instances of the child type--think of entitysets something like tables just that can contain polymorphic types rather than a single rectangular type.

     

    What did you do to verify your statement above that when you tried passing the basetype entityset, it "only added the base type"?

     

    To be more concrete, if I have a type Order and a type InternationalOrder which inherits from Order and I have a single entityset of Orders (some of which are InternationalOrders), then I can persist a new InternationalOrder by creating an instance of that class and then passing it to AddObject along with the entityset name "Orders".  The system will detect the object type and use it to determine how to persist the object (that it must persist the extra properties on InternationalOrder, etc.), but the entityset name is required because there could in theory be more than one entityset for entities of the same type (eg. WestRegionOrders in one entityset and CentralRegionOrders in another, etc.)

     

    If you have a case where it seems that not all the info is persisting, then let's dig into it a bit and figure out what is going on.

     

    - Danny

    Sunday, September 16, 2007 10:27 PM

All replies

  • Actually, passing the base type entityset is probably exactly what you want to do.  Normally you will have an entityset that contains both instances of the basetype and instances of the child type--think of entitysets something like tables just that can contain polymorphic types rather than a single rectangular type.

     

    What did you do to verify your statement above that when you tried passing the basetype entityset, it "only added the base type"?

     

    To be more concrete, if I have a type Order and a type InternationalOrder which inherits from Order and I have a single entityset of Orders (some of which are InternationalOrders), then I can persist a new InternationalOrder by creating an instance of that class and then passing it to AddObject along with the entityset name "Orders".  The system will detect the object type and use it to determine how to persist the object (that it must persist the extra properties on InternationalOrder, etc.), but the entityset name is required because there could in theory be more than one entityset for entities of the same type (eg. WestRegionOrders in one entityset and CentralRegionOrders in another, etc.)

     

    If you have a case where it seems that not all the info is persisting, then let's dig into it a bit and figure out what is going on.

     

    - Danny

    Sunday, September 16, 2007 10:27 PM
  • Excuse me Daniel, was an incorrect database verification due to I was using three levels of inheritance. Thank you.

     

    Vítor

    Tuesday, September 18, 2007 2:14 PM