question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OHLC should implement IComparable

See original GitHub issue

Hello,

Im just saving your OHLC to Entity framework with Sqllight Core and when im trying to make queries using linkq i got this :

Property ‘HistoricRates.OhlcItem’ cannot be used as a key because it has type ‘OHLC’ which does not implement ‘IComparable<T>’, ‘IComparable’ or ‘IStructuralComparable’. Use ‘HasConversion’ in ‘OnModelCreating’ to wrap ‘OHLC’ with a type that can be compared.’

public static List<OHLC> GetOhlcList(string cryptoCoinName, Granularity granularity)
{
     using (SqliteDbContext dbContext = new SqliteDbContext())
     {

      var c =  dbContext.HistoricRates.Where(s => s.MarketItemName == MarketItemName )     // Multiple market products
                                                    .Where(s => s.GranularityItem == granularity)                   // Multiple timeSpan  5 min 1 hour etc
                                                    .Select(s => new
                                                    {
                                                         s = s.OhlcItem
                                                    }).ToList();
     }
}


public class HistoricRates
{
        public string MarketItemName { get; set; }
        public Granularity GranularityItem { get; set; }
        public OHLC OhlcItem { get; set; }
}

Would be cool if OHLC had IComparable<T> interface !

If you have better idea on how to implement that im open to new ideas ! 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
swhardencommented, Feb 23, 2021

I think that just makes it more ambiguous what the comparison does.

I now am unsure that this feature is a good choice.

Especially when a wrapper class with behavior of the user’s choosing is trivially implemented

After thinking about it some more, I feel the same way. To me it doesn’t make intuitive sense to sort or compare candles anyway! Adding extra code just to support an external frameworks is probably not a pattern we want to get into the habit of adopting 😅

1reaction
bclehmanncommented, Feb 23, 2021

I agree DateTime may make more sense as the field to compare, but unfortunately I think that just makes it more ambiguous what the comparison does. I now am unsure that this feature is a good choice. If we stored individual points of a scatterplot as a Point struct it would be the same issue, in certain contexts it makes more sense to compare on the x or y value but in general it just adds more confusion.

I’m of the opinion that a feature shouldn’t be added if its behaviour (as interpreted by the user, not the compiler or runtime) is ambiguous. Especially when a wrapper class with behaviour of the user’s choosing is trivially implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

At least one object must implement IComparable
At least one object must implement IComparable. " when trying to add a second player, the first one works, but the second one...
Read more >
IComparable Interface (System)
Defines a generalized type-specific comparison method that a value type or class implements to order or sort its instances.
Read more >
RolloverModifier OHLC Problem | WPF Chart Forums
Hi there, Please,take a look at our SciChart Trader example. Notice, how labels data is bound to RolloverModifier.RolloverData.SeriesInfo object; to create ...
Read more >
At least one object must implement icomparable. LINQ C# - ...
You need to implement IComparable interface, to provide compare versus another instance. In the case of your code problem, will occurs at ...
Read more >
Time series manipulation in C#
There are no restriction on the types of keys and values, but some operations are only available for keys that can be ordered...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found