ServiceStack.OrmLite加入Skip并采用Oracle DB

时间:2014-11-05 19:36:34

标签: servicestack ormlite-servicestack

我正在尝试填充包含两个不同表格的网格。所以我需要:

1)在两个表之间加入功能。

2)跳过/采取限制结果。

3)表格中的总行数

我想使用SqlExpression完成它,因为它似乎是ServiceStack.OrmLite中最受支持的。但是,当我执行Skip and Take时,它返回" ORA-00918:列模糊定义"因为这两个表有一些同名的列。

代码如下:

var dbCustomersQuery2 = db.From<USER>()
.LeftJoin<USER, USERPROFILE>((user, profile) => user.Id == profile.USER_ID)
.Where<USER>(user => user.USERNAME == "sangee.ram")
.Where<USERPROFILE>(profile => profile.PROFILEID == 442);
var result = db.Select<ViewModel>(dbCustomersQuery2.Skip(1).Take(5));

这是堆栈跟踪:

   at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteReader(Boolean requery, Boolean fillRequest, CommandBehavior behavior)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
   at ServiceStack.OrmLite.OrmLiteCommand.ExecuteReader()
   at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.ExecReader(IDbCommand dbCmd, String sql)
   at ServiceStack.OrmLite.OrmLiteResultsFilterExtensions.ConvertToList[T](IDbCommand dbCmd, String sql)
   at ServiceStack.OrmLite.OrmLiteReadCommandExtensions.SqlList[T](IDbCommand dbCmd, String sql, Object anonType)
   at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.<>c__DisplayClass10`1.<Select>b__f(IDbCommand dbCmd)
   at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter)
   at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Exec[T](IDbConnection dbConn, Func`2 filter)
   at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Select[T](IDbConnection dbConn, ISqlExpression expression, Object anonType)
   at LO.Leads.UI.Tests.UserSecurityTests.CanQueryUserSecurity() in c:\Git\Cons.Orig.Lead\src\LO.Leads.UI\LO.Leads.UI.Tests\UserSecurityTests.cs:line 68

1 个答案:

答案 0 :(得分:0)

我注意到的第一件事是你包含了跳过并进入最后一个select命令,一旦我移出它我不再得到异常。

var userQuery = db.From<USER>()
    .LeftJoin<USER, USERPROFILE>((user, profile) => user.Id == profile.USER_ID)
    .Where<USER>(user => user.USERNAME == "sangee.ram")
    .Where<USERPROFILE>(profile => Sql.In(profile.PROFILEID, new[] { 1, 441, 442, 452 }));

var result = db.Select<ViewModel>(userQuery)
    .Skip(1)
    .Take(2);

Assert.NotNull(result);

当我运行此测试时,它从可能的4行中返回2行(第2行和第3行)。

希望这有帮助, 斯蒂芬