c1-cms

Get Data Reference Data In Razor Function


I have three Global Data Type Tour Hotel Airline

I have Created A Razor Function To Display Tour With Relevant Hotel And Airline Information But I Cant Get Airline and Hotel Data In My Function Here Is the Code :

    @foreach (var Tour in Data.Get<Countries.Tour>())
{
     @Tour.Airline.Name 
    <img src='~/media(@Tour.Thumb)'  />
}

@Tour.Airline.Name is not working I cant save the function neither @Tour.Airline which only output the airline Guid not the airline name .

so what do you recommend ? using xslt function ? or creating helper function to pass airline Guid and get the airlone data back which I think make the system a bit complex.


Solution

  • The C1 Data layer will return "a flat structure" consisting of simple fields (string, int, guid etc) and not a deep object structure.

    You need to do join with the Airline type, something like this:

    var myList = from tour in Data.Get<Countries.Tour>()
    join airline in Data.Get<Countries.Airline>() on tour.Airline equals airline.Id
    select new { airline.Name, tour.Thumb};
    
    @foreach (var element in myList)
    {
         @element.Name 
        <img src='~/media(@element.Thumb)'  />
    }
    

    See What is the syntax for an inner join in LINQ to SQL?