Multiple conditions in where clause

Thread is closed for posting
2 posts, 1 answers
  1. Rohan
    Rohan avatar
    6 posts
    Member since:
    Apr 2009

    Posted 06 May 2009 Link to this post

    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);
      }
    }

  2. Answer
    Zoran
    Admin
    Zoran avatar
    534 posts

    Posted 10 May 2009 Link to this post

    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.
Back to Top