使用 PetaPoco,您应该能够使用Exists
API 中的方法重载,如下所示。
/// <summary>
/// Checks for the existance of a row matching the specified condition
/// </summary>
/// <typeparam name="T">The Type representing the table being queried</typeparam>
/// <param name="sqlCondition">The SQL expression to be tested for (ie: the WHERE expression)</param>
/// <param name="args">Arguments to any embedded parameters in the SQL statement</param>
/// <returns>True if a record matching the condition is found.</returns>
public bool Exists<T>(string sqlCondition, params object[] args)
所以你应该可以打电话:
var exists = myDB.Exists<myTable>("field = 'value'");