This is a migrated thread and some comments may be shown as answers.

Multiple conditions in where clause

1 Answer 91 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rohan
Top achievements
Rank 1
Rohan asked on 07 May 2009, 03:08 AM

Hi there, 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);
  }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Zoran
Telerik team
answered on 10 May 2009, 02:28 PM
Hi Rohan,

Yes you are right this is a functionality that our Linq support misses. I'd suggest you use some of the numerous workarounds available for this case temporarily before we add this in our Linq implementation. The issue is already on our to-do list. Your Telerik points have been updated.


All the best,
Zoran
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
General Discussions
Asked by
Rohan
Top achievements
Rank 1
Answers by
Zoran
Telerik team
Share this question
or