locked
Defining relationships in a custom provider RRS feed

  • Question

  • I am following Alex James' series on building a custom data provider. Trying to get ahead of the game, however, I got stuck on defining relationships.

    Say I have two ResourceSets "Products" and "Companies", where Product.VendorId references a company. How should I define IDataServiceMetadataProvider.GetResourceAssociationSet() to represent that relationship correctly?

    Thanks, Sven
    Sunday, February 21, 2010 9:35 PM

Answers

  • Hi,

    Short answer: you need to define a new property of kind ResourcePropertyKind.ResourceSetReference (1:many) or ResourceReference (1:1) with the ResourceType being the resource type of the target of the relationship (in your case the Company). Let's call this property a "Company".
    Then from the GetResourceAssociationSet you need to return something like:
    new ResourceAssociationSet(
        "MyAssociationName",
        new ResourceAssociationSetEnd(productsResourceSet, productResourceType, productCompanyProperty),
        new ResourceAssociationSetEnd(companyResourceSet, companyResourceType, null));

    Long answer: wiat for Alex to post about relationships :-)

    Thanks,
    Vitek Karas [MSFT]
    • Marked as answer by svenk___ Monday, February 22, 2010 6:50 PM
    Monday, February 22, 2010 12:18 PM
    Moderator

All replies

  • Hi,

    Short answer: you need to define a new property of kind ResourcePropertyKind.ResourceSetReference (1:many) or ResourceReference (1:1) with the ResourceType being the resource type of the target of the relationship (in your case the Company). Let's call this property a "Company".
    Then from the GetResourceAssociationSet you need to return something like:
    new ResourceAssociationSet(
        "MyAssociationName",
        new ResourceAssociationSetEnd(productsResourceSet, productResourceType, productCompanyProperty),
        new ResourceAssociationSetEnd(companyResourceSet, companyResourceType, null));

    Long answer: wiat for Alex to post about relationships :-)

    Thanks,
    Vitek Karas [MSFT]
    • Marked as answer by svenk___ Monday, February 22, 2010 6:50 PM
    Monday, February 22, 2010 12:18 PM
    Moderator
  • Hi Vitek,

    thanks for your response. I  already thought of something like that. My mistake was to define the company property as integer, i. e. as foreign key in a relational sense. I changed it to return a Company, now it works.

    Sven
    Monday, February 22, 2010 7:24 PM