locked
How to Access entities associated with another custom entity in and n-n relationship RRS feed

  • Question

  • Hallo Friends!

    I have a custom entity restaurant and it has a relationship n-n with caterers. I want to access one property eg. Cost/Plate for the caterer for all the caterers in the list of my restaurant entity eg: Restaurant Blue Garden has caterers McDonell with propery 12€ per plate and Govinda's with 8€ per plate and then add them to give an average cost per plate.

     

    Thanking you in advance,

     

    Sebastian

    Thursday, September 2, 2010 1:48 PM

Answers

All replies

  • Thursday, September 2, 2010 2:02 PM
    Moderator
  • Thanks for your reply Mahender and I have read the related Forum but still I am unable to get any clear idea on how to implement it.
    Thursday, September 2, 2010 2:38 PM
  • Are you trying to do this in a report, display the average value on a record or something different?  the post is difficult to follow 

    Regards, Donna

    Saturday, September 4, 2010 2:49 AM
  • You can display the Cost/Plate attribute in the list view (by modifyling the Asscoiated View to display that property) so you can see the attribute in the list, BUT you will only be able to determine the average value of all the records in the list by writing custom code.

    One way of doing this would be to add an additional attribute on the Restaurant entity (Average Cost/Plate) and each time a caterer is added you call your own code (plugin) to re-calculate the average based on all the caterer records attached and then update the Average attribute on the restaurant.

    Sunday, September 5, 2010 12:12 AM
  • If Cost/plate has a 1:N relationship with the caterer, you can display the value in a view.  As far as calculating the average, there are several ways you could do it.  As Donna mentioned, a SSRS report could show this, also you could have a process that runs that updates the average on the restaurant based on the cost/plate of the caterers.  A plugin could do it, also you could use Scribe insight and have a batch process that calculates and updates the avg cost/plate based on the caterers associated with the restaurant.
    Sunday, September 5, 2010 1:14 AM
    Moderator
  • Hi Donna,

    Sorry for the late reply and unclear post. It was the weekend and I wasn't at work. No I am not trying to do this in a report but it should just display somewhere on the page basically I don't know how to access the information. I was trying it using a plug-in and trying to write code using the LINQ services integrated in CRM 4.0 but it is not yet working. The main problem is using an entity which we receive in context how to access the entities related to that entity and then on accessing that entity access its attributes. This I was unable to implement as of yet. Thank you for your reply,

    YS,

     

    Sebastian

    Monday, September 6, 2010 7:25 AM
  • Thank you Guy Riddle for replying but due to my unclear post I haven't been able to express my problem properly. Sorry for that. My main problem is is using an entity which we receive in context how to access the entities related to that entity and then on accessing that entity access its attributes. I am trying via MS LINQ integration but I am stuck there due to some complexities I am unable to understand!!!

    Monday, September 6, 2010 7:28 AM
  • Hi Joek,

     

    Thanks for your reply! SSRS report! ok I will try using it. Scribe insight??? I don't know what is that. I will try to find out about it and use it. Thank you again.

    Sebastian

    Monday, September 6, 2010 7:31 AM
  • if you can to fetch related entities, you can write a function to fetch all related entity records based on the ID that you are getting from context. Once you will get all records you can process their attributes one by one.


    Mahain : http://mahenderpal.wordpress.com
    Monday, September 6, 2010 7:33 AM
    Moderator
  • Mahinder if I get you right are you saying that I should use the Fetch method to query the relationship entity which stores data of the associated entities in this example: I should query RestaurantResCatererCaterer considering Restaurant and Caterer as the Entity schema name and ResCaterer as the relationshipName?
    Monday, September 6, 2010 8:31 AM
  • I am not sure you are using correct relationship name or not, Why don't you go through this wonderful post it also contains example to fetch relationship record with relationship explanation


    Mahain : http://mahenderpal.wordpress.com
    Monday, September 6, 2010 8:50 AM
    Moderator
  • Hey thanks! I will read it now! Your links are always super cool. The last time even the video post you had sent me was of great benefit. On searching we can never find such things. :)
    Monday, September 6, 2010 8:56 AM
  • you are welcome !!! we are here to help each other.
    Mahain : http://mahenderpal.wordpress.com
    Monday, September 6, 2010 9:09 AM
    Moderator