鉴于以下定义:
[Alias("USERS")]
public partial class USER : IHasId<string>
{
[Alias("USER_ID")]
[Required]
public string Id { get; set;}
[Required]
public string USERNAME { get; set;}
[Required]
public string PASSWORD { get; set;}
[Required]
public decimal ACTIVESTATUS { get; set;}
[Required]
public DateTime CREATIONDATE { get; set;}
[Required]
public DateTime LASTMODIFIEDDATE { get; set;}
[Required]
public DateTime ACTIVATEDATE { get; set;}
[Required]
public DateTime DEACTIVATEDATE { get; set;}
[Required]
public decimal ISACTIVEDIRECTORY { get; set;}
[Required]
public string CLIENTIDS { get; set;}
}
[Alias("USERPROFILES")]
public partial class USERPROFILE : IHasId<decimal>
{
[Alias("USERPROFILEID")]
[Required]
public decimal Id { get; set;}
[Required]
public decimal PROFILEID { get; set;}
[Required]
public string USER_ID { get; set;}
[Required]
public decimal ISPRIMARY { get; set;}
}
[Fact]
public void CanQueryUserSecurity()
{
string connection = ConfigurationManager.AppSettings["MyConnKey"];
using (IDbConnection db = connection.OpenDbConnection())
{
var result = db.Select<USER>(q =>
q.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 }))
.Limit(skip: 1, rows: 2));
Assert.NotNull(result);
}
}
抛出此异常的结果。
DEBUG: SELECT * FROM (
SELECT "_ss_ormlite_1_".*, ROWNUM RNUM FROM (
SELECT USERS.USER_ID AS Id, USERS.USERNAME, USERS."PASSWORD", USERS.ACTIVESTATUS, USERS.CREATIONDATE, USERS.LASTMODIFIEDDATE, USERS.ACTIVATEDATE, USERS.DEACTIVATEDATE, USERS.ISACTIVEDIRECTORY, USERS.CLIENTIDS
FROM USERS LEFT JOIN USERPROFILES ON (USERS.USER_ID = USERPROFILES.USER_ID)
WHERE (USERS.USERNAME = 'sangee.ram') AND USERPROFILES.PROFILEID In (1,441,442,452) ORDER BY USER_ID) "_ss_ormlite_1_"
WHERE ROWNUM <= 1 + 2) "_ss_ormlite_2_" WHERE "_ss_ormlite_2_".RNUM > 1
Oracle.DataAccess.Client.OracleExceptionORA-00918: column ambiguously defined
at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable)
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.OrmLiteResultsFilterExtensions.ExprConvertToList(IDbCommand dbCmd, String sql)
at ServiceStack.OrmLite.OrmLiteExecFilter.Exec(IDbConnection dbConn, Func`2 filter)
at LO.Leads.UI.Tests.UserSecurityTests.CanQueryUserSecurity() in UserSecurityTests.cs: line 35
看起来'ORDER BY USER_ID'需要别名,我不太了解SqlExpression类来修改它。
更新
如果我正确地使用gen'dql语句并别名'ORDER BY USERS.USER_ID ',则语句执行
谢谢你, 斯蒂芬