使用OrmLite SqlExpression与Mysql时检测到潜在的非法片段?

时间:2015-03-13 17:40:49

标签: mysql servicestack ormlite-servicestack

当我尝试执行以下行时:

var vehicles = db.Select<VehicleResponse>(q => q.Select(
"SELECT make, model, year, color FROM Vehicles").Limit(skip: 0, rows: 10));

我收到错误:

Potential illegal fragment detected: SELECT make, model, year, color FROM Vehicles

如果我执行以下操作,我不会收到错误:

 var vehicles = db.Select<VehicleResponse>(
 "SELECT make, model, year, color FROM Vehicles").ToList();

1 个答案:

答案 0 :(得分:1)

执行自定义SQL时,通常应使用Custom Sql API's db.SqlList<T>

如果要在键入的SqlExpression中使用自定义SQL,则应使用Unsafe* API绕过任何自定义SQL检测。

但对于SqlExpression的Select API,您应该只添加&#34; SELECT ...&#34; SQL语句的一部分,例如:

var vehicles = db.Select<VehicleResponse>(q => q.From<Vehicle>().Select(
    "make, model, year, color").Limit(skip: 0, rows: 10));

虽然在这种情况下我不会为指定列列表而烦恼,只是让它选择所有匹配的列,例如:

var vehicles = db.Select<VehicleResponse>(q => 
    q.From<Vehicle>().Limit(skip: 0, rows: 10));