我有一個簡單的類:用ActiveRecord和LINQ問題查詢
public class User : ActiveRecordLinqBase<User>
{
[PrimaryKey(Column = "user_id", Length = 20)]
public string Id { get; set; }
[Property(Column = "password", Length = 16)]
public string Password { get; set; }
...
}
,我創建了以下存儲庫:
public class SqlRepository<T> : IRepository<T> where T : ActiveRecordLinqBase<T>, new() {
public void Add(T entity) {
entity.SaveAndFlush();
}
public void Remove(T entity) {
entity.DeleteAndFlush();
}
public void Modify(T entity) {
entity.UpdateAndFlush(); ;
}
...
public IEnumerable<T> FindAll(Func<T, bool> predicate) {
return ActiveRecordLinqBase<T>.Queryable.Where(predicate);
}
}
現在,運行下面的單元測試(針對MySQL數據庫時):
[Test]
public void Test_Sample() {
var repo = new SqlRepository<T>();
repo.Add("john.doe", "keyword1");
repo.Add("other.user", "keyword2");
var users = repo.FindAll(x => x.Username.Contains("john")).ToList();
Assert.AreEqual(1, users.Count);
}
...我碰到下面的SQL查詢:
選擇this_.user_id爲user1_0_0_,this_.password爲password0_0_,this_.role作爲role0_0_來自用戶的THIS_
哪裏WHERE
條款?
如果我這樣做,而不是直接在相同的測試下...
var users = User.Queryable.Where(x => x.Username.Contains("john"));
我碰到下面的SQL:
選擇this_.user_id爲user1_0_0_,this_.password爲password0_0_, this_.role作爲role0_0_來自用戶的THIS_ WHERE this_.user_id喜歡P0;?P0 = '%約翰%'
難道我做錯了什麼?
這兩個查詢有什麼區別?
編輯:我也試圖與
return ActiveRecordLinq.AsQueryable<T>().Where(predicate);
沒有成功。
花了大約2.5小時:/非常感謝你;) –