SequenceContainsNoElements Exception when calling connection.Get<T>()


When making a call to SQLite.SQLiteConnection.Get<T>(object primaryKey), I get an exception thrown, possibly due to the table or record not being available. This feels like a bug to me. If the table or record isn’t there, it should simply return null rather than throw an exception.

This is for Android v3.3.1.0

Is there a workaround for this?

Edit: some more detail:

System.InvalidOperationException: Sequence contains no elements
  at System.Linq.Enumerable.First[SerializableKeyValuePair] (IEnumerable`1 source) [0x00060] in <filename unknown>:0 
  at SQLite.SQLiteConnection.Get[SerializableKeyValuePair] (System.Object pk) [0x00028] in <filename unknown>:0 


Hello @kensykora

I believe you are referring to this specific portion of the client API, correct? In this case I think the reasoning for throwing the exception makes sense in that you are asking for a very specific item to exist, something you expect to be there as you already know the primary key, thus when it is not found, this is considered an exceptional situation, no pun intended. Alternatively, if you were just searching for something, in a situation where you were not sure that it existed, returning null, or an Option type may be a more preferred approach which is what I believe you were referring to. Instead of returning null, an alternative might be to return an Either<Error, Object>, however this client library does not deviate too far from the upstream where that is not present. Does that address your question?