'GET<TModel> NOT by primaryKEY

I am using this function to query a table by its primary ID.

 public virtual List<TModel> LoadAllWithChildren()
 {
     lock(Connection)
     {
         var result = LoadAll();

         foreach (var item in result)
         {
             try
             {
                 Connection.GetChildren(item);
             }
             catch (Exception e)
             {
                DebugTraceListener.Instance.WriteLine(GetType().Name,
                     "Can not load Child for itemType: " + item.GetType().Name + " reason: " + e);
             }
         }

         return result;
     }
 }

But this always return results in regards to the primary key. The table I am querying on looks like this:

enter image description here

So when I do this, I get all entries in this table (not just the ones you see in the picture, those are the ones that I want)

So I did a small workaround:

 var persistance = await Task.Run(() => PersistenceService.PresentationSequence.LoadAllWithChildren());
                 List<PresentationSequence> resSequence = new List<PresentationSequence>();
                 foreach(var elem in persistance)
                     if (elem.PresentationId == 166)
                         resSequence.Add(elem);

The result is the list as seen in the picture.

This, however, is slow.

Is there a way to use another SQlite function that will give me the list already filter for "166" in "presentationID"?

(So no local work is done)

EDIT: I have tried using this function:

public virtual TModel LoadById(int id)
        {
            lock(Connection)
            {
                try
                {
                    var result = Connection.Get<TModel>(id);
                    return result;
                }
                catch (Exception ex)
                {
                    DebugTraceListener.Instance.WriteLine(GetType().Name, $"Cannot find item with ID: {id}\n\n{ex}");
                    return null;
                }
            }
}

But this will only take the primary key in. But I want to query for presentation ID and not get a single result from the ID column



Solution 1:[1]

I ended up going with the query function:

try
                {
                    var result = Connection.Query<TModel>(querystring);
                    return result;
                }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 innom