Dear Durga,
Thank you for your response and for the sample project.
I think the main difference between the sample and my project is that I'm using EF Core to retrieve the data. The underlying database has relationships between various tables - these get converted into relationship properties within the relevant classes in the solution.
In my case, I've got a Prices table and an Instruments table - one instrument, many prices. My Instruments class is as follows:
public partial class Instruments
{
public Instruments()
{
Holdings = new HashSet<Holdings>();
Prices = new HashSet<Prices>();
}
public int InstrumentId { get; set; }
public string InstrumentName { get; set; }
public string Ussymbol { get; set; }
public string Ftsymbol { get; set; }
public string YahooSymbol { get; set; }
public string Sedol { get; set; }
public string Isin { get; set; }
public string LocalCurrency { get; set; }
public short IsFund { get; set; }
public DateTime? CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
public virtual ICollection<Holdings> Holdings { get; set; }
public virtual ICollection<Prices> Prices { get; set; }
}
While my Prices class looks like:
public partial class Prices
{
public int PriceId { get; set; }
public int InstrumentId { get; set; }
public DateTime PriceDate { get; set; }
public decimal CurrentPriceUsd { get; set; }
public decimal CurrentPriceGbp { get; set; }
public decimal OpenPriceUsd { get; set; }
public decimal OpenPriceGbp { get; set; }
public decimal HighPriceUsd { get; set; }
public decimal HighPriceGbp { get; set; }
public decimal LowPriceUsd { get; set; }
public decimal LowPriceGbp { get; set; }
public decimal PreviousClosePriceUsd { get; set; }
public decimal PreviousClosePriceGbp { get; set; }
public DateTime? CreatedDate { get; set; }
[JsonIgnore]
[IgnoreDataMember]
public virtual Instruments Instrument { get; set; }
}
These classes are generated automatically by using the 'dotnet ef dbcontext scaffold' approach. Without those decorators on 'public virtual Instruments Instrument', I get the circular reference error when I open a chart that is in the Detail Template of a grid showing a list of instruments:
Error: System.AggregateException: One or more errors occurred. (Self referencing loop detected with type 'ComputenceWebApp.Data.Prices'. Path 'series[0].dataSource[0].Instrument.Prices'.)
The data source for the page is the Instruments, plus an Include to get the related prices:
return await _context.Instruments.OrderBy(s => s.InstrumentName)
.Include(m => m.Prices)
.ToListAsync();
The chart itself is rendered on the page within a tab:
<TabItem>
<ChildContent>
<TabHeader Text="Chart View"></TabHeader>
</ChildContent>
<ContentTemplate>
<SfChart Title="Price History">
<ChartPrimaryXAxis ValueType="ValueType.DateTime"></ChartPrimaryXAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@instrument.Prices.Where(x => x.CurrentPriceUsd > 0).OrderBy(p => p.PriceDate)" XName="@nameof(Prices.PriceDate)" YName="@nameof(Prices.CurrentPriceUsd)" Type="ChartSeriesType.Line"></ChartSeries>
</ChartSeriesCollection>
</SfChart>
</ContentTemplate>
</TabItem>
All works beautifully as long as the Prices class has those two decorators ([JsonIgnore] and [IgnoreDataMember]) on the relationship property.
I had experienced exactly the same error message with the Grid. I posted a question and was lucky enough to get the response that v18.2.0.44 would fix it. Which it did. That's why I was wondering if there are still cases where you still need to use the serialization/deserialization methods.
Does the above shed any light at your end on where the problem might lie?
Many thanks and best wishes,
Sebastian