Telerik OpenAccess 和 where 子句中的多个条件
我刚刚编写了一些单元测试,令我恐惧的是它失败了。
这是我的测试...
[TestMethod]
public void FetchWithMoreThanOneConditionUsingKnownTypes()
{
using (var scope = EntityObjectScopeProvider.GetNewObjectScope())
{
var temp = new TempClient() { FirstName = "Rohan", Surname = "West" };
var entity = scope.Extent<ClientEntity>().Where(c => temp.FirstName == c.FirstName && temp.Surname == c.Surname).FirstOrDefault();
Assert.IsNotNull(entity);
Assert.AreEqual(entity.FirstName, temp.FirstName);
Assert.AreEqual(entity.Surname, temp.Surname);
}
}
它给了我以下异常,无法将“Entities.Testing.TempClient”类型的对象转换为“System.String”类型。 这是正常的吗,我希望不是,以下测试工作正常。 我猜解析表达式时出现问题......这个会被修复吗?
[TestMethod]
public void FetchWithMoreThanOneConditionUsingTempVariables()
{
using (var scope = EntityObjectScopeProvider.GetNewObjectScope())
{
var temp = new TempClient(){ FirstName = "Rohan", Surname = "West" };
string firstname = temp.FirstName;
string surname = temp.Surname;
var entity = scope.Extent<ClientEntity>().Where(c => c.FirstName == firstname && c.Surname == surname).FirstOrDefault();
Assert.IsNotNull(entity);
Assert.AreEqual(entity.FirstName, temp.FirstName);
Assert.AreEqual(entity.Surname, temp.Surname);
}
}
I have just written a few unit tests and to my horror it failed.
Here is my test...
[TestMethod]
public void FetchWithMoreThanOneConditionUsingKnownTypes()
{
using (var scope = EntityObjectScopeProvider.GetNewObjectScope())
{
var temp = new TempClient() { FirstName = "Rohan", Surname = "West" };
var entity = scope.Extent<ClientEntity>().Where(c => temp.FirstName == c.FirstName && temp.Surname == c.Surname).FirstOrDefault();
Assert.IsNotNull(entity);
Assert.AreEqual(entity.FirstName, temp.FirstName);
Assert.AreEqual(entity.Surname, temp.Surname);
}
}
it is giving me the following exception, Unable to cast object of type 'Entities.Testing.TempClient' to type 'System.String'. Is this normal, i hope not, The following test works correctly. I guess there is a problem when parsing the expression... Will this be fixed?
[TestMethod]
public void FetchWithMoreThanOneConditionUsingTempVariables()
{
using (var scope = EntityObjectScopeProvider.GetNewObjectScope())
{
var temp = new TempClient(){ FirstName = "Rohan", Surname = "West" };
string firstname = temp.FirstName;
string surname = temp.Surname;
var entity = scope.Extent<ClientEntity>().Where(c => c.FirstName == firstname && c.Surname == surname).FirstOrDefault();
Assert.IsNotNull(entity);
Assert.AreEqual(entity.FirstName, temp.FirstName);
Assert.AreEqual(entity.Surname, temp.Surname);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
联系 Telerik 支持后发现这是不可能的。
After contacting Telerik support, it turned out not to be possible.