Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15206

[RESOLVED] PetaPoco: Operation could destabilize the runtime

$
0
0
At work, we use PetaPoco as our ORM and it works great when using strongly typed objects.

However, I have a requirement to allow users (specifically just one user) enter their own queries to return an array of objects that will then be used on the front-end using the PivotTable.js library.

The issue I am running into is that when I go to query the user entered SQL and I pass a dynamic or an object as the type, I get the following exception:
Quote:

Operation could destabilize the runtime
For reference, this is the code that I'm using:
Code:

public List<object> ExecuteSql(int adHocQueryId)
{
    _database.EnableAutoSelect = false;
    var adHocQuery = Get(adHocQueryId);
    var results = _database.Query<object>(adHocQuery.Sql).ToList();
    _database.EnableAutoSelect = true;

    return results;
}

The Get method is defined as the following:
Code:

public AdHocQueryViewModel Get(int AdHocQueryId)
{
    var filter = new Dictionary<string, dynamic>
    {
        { "AdHocQueryId", AdHocQueryId }
    };
    var records = Query(filter);

    if (!records.Any())
    {
        throw new SystemError($"No record found for AdHocQueryId {AdHocQueryId}");
    }

    if (records.Count > 1)
    {
        throw new SystemError($"More than one record found for AdHocQueryId {AdHocQueryId}");
    }

    return records.Single();
}

The Query method ultimately hits the IDatabase's Query method using a List<AdHocQueryViewModel> as the strongly typed object.

I was thinking about writing a wrapper to just return the collection of datarows, but before I started down that path, I wanted to see if anyone else ran into this same issue.

Viewing all articles
Browse latest Browse all 15206


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>