我有一个简单的类:用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小时:/非常感谢你;) –