Contains not working in Where clause using IEnumerable

3 posts, 0 answers
  1. Chris
    Chris avatar
    40 posts
    Member since:
    Feb 2009

    Posted 21 Nov 2011 Link to this post

    I believe the following used to work in the previous release (2011.2.713):

    public void Delete(IEnumerable<Guid> pTokenIds)
    {
        IEnumerable<Token> tokens = _Context.Tokens.Where(t => pTokenIds.Contains(t.TokenId));
        _Context.Delete(tokens);
        _Context.SaveChanges();
    }

    Now when I do this with release 2011.3.1116, I get the following stack trace:

    Telerik.OpenAccess.Exceptions.DataStoreException: Error setting query parameter {1} = 'System.Linq.Enumerable+WhereSelectEnumerableIterator`2[Telerik.Web.UI.GridItem,System.Guid]' at PreparedStatement index 1 in
    SELECT a.[TokenId] AS COL1, a.[ConfirmationDate] AS COL2, a.[CreationDate] AS COL3, a.[Deleted] AS COL4, a.[DeletionDate] AS COL5, a.[GroupName] AS COL6, a.[OrganizationId] AS COL7, a.[UserEmailAddress] AS COL8 FROM [Tokens] a WHERE (a.[TokenId] IN (NULL) AND (1=0)) ORDER BY a.[TokenId] 
    (set event logging to all to see parameter values)
    System.ArgumentOutOfRangeException: Wrong type of instance, expected System.Guid
    Parameter name: instance
    Actual value was System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[Telerik.Web.UI.GridItem, Telerik.Web.UI, Version=2011.3.1115.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4],[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].
       at OpenAccessRuntime.Data.AdoTypeConverterUtils.Check[T](Object instance)
       at OpenAccessRuntime.Data.GuidConverter.Write(DataHolder& data)
       at OpenAccessRuntime.Relational.metadata.RelationalSimpleField.setQueryParam(PreparedStatement ps, Int32 firstParam, Object val)
       at OpenAccessRuntime.Relational.fetch.SqlBuffer.setParamsOnPS(ModelMetaData jmd, SqlDriver driver, PreparedStatement ps, Object[] parameters, String sqlParam) System.ArgumentOutOfRangeException: Wrong type of instance, expected System.Guid
    Parameter name: instance
    Actual value was System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[Telerik.Web.UI.GridItem, Telerik.Web.UI, Version=2011.3.1115.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4],[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].
       at OpenAccessRuntime.Data.AdoTypeConverterUtils.Check[T](Object instance)
       at OpenAccessRuntime.Data.GuidConverter.Write(DataHolder& data)
       at OpenAccessRuntime.Relational.metadata.RelationalSimpleField.setQueryParam(PreparedStatement ps, Int32 firstParam, Object val)
       at OpenAccessRuntime.Relational.fetch.SqlBuffer.setParamsOnPS(ModelMetaData jmd, SqlDriver driver, PreparedStatement ps, Object[] parameters, String sqlParam) ---> System.ArgumentOutOfRangeException: Wrong type of instance, expected System.Guid
    Parameter name: instance
    Actual value was System.Linq.Enumerable+WhereSelectEnumerableIterator`2[[Telerik.Web.UI.GridItem, Telerik.Web.UI, Version=2011.3.1115.40, Culture=neutral, PublicKeyToken=121fae78165ba3d4],[System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].
       at OpenAccessRuntime.Data.AdoTypeConverterUtils.Check[T](Object instance)
       at OpenAccessRuntime.Data.GuidConverter.Write(DataHolder& data)
       at OpenAccessRuntime.Relational.metadata.RelationalSimpleField.setQueryParam(PreparedStatement ps, Int32 firstParam, Object val)
       at OpenAccessRuntime.Relational.fetch.SqlBuffer.setParamsOnPS(ModelMetaData jmd, SqlDriver driver, PreparedStatement ps, Object[] parameters, String sqlParam)
       --- End of inner exception stack trace ---
       at OpenAccessRuntime.ExceptionWrapper.Throw()
       at OpenAccessRuntime.storagemanager.logging.LoggingStorageManager.fetchNextQueryResult(ApplicationContext context, RunningQuery runningQuery, Int32 skipAmount)
       at OpenAccessRuntime.DataObjects.SynchronizedPMProxy.getNextQueryResult(QueryResultWrapper aQrs, Int32 skipAmount)
       at OpenAccessRuntime.DataObjects.ForwardQueryResult.Initialize(Int32 indexParam)
       at OpenAccessRuntime.DataObjects.ForwardQueryResult.get_Item(Int32 indexParam)
       at OpenAccessRuntime.DataObjects.SynchronizedQueryResult.get_Item(Int32 index)
       at OpenAccessRuntime.ListEnumerator.setCurrent(Int32 _pos)
       at OpenAccessRuntime.ListEnumerator.Move(Int32 relative)
       at OpenAccessRuntime.DataObjects.PMProxy.deletePersistentAll(IEnumerator enr)
       at VirtualOffice.Controllers.TokenController.Delete(IEnumerable`1 pTokenIds) in C:\inetpub\wwwroot\VirtualOffice\Common Libraries\VirtualOffice.Controllers\TokenController.cs:line 172
       at Controls_ObjectPanes_Invitations.OnInvitationToolbarButtonClick(Object sender, RadToolBarEventArgs e) in c:\inetpub\wwwroot\VirtualOffice\Web\Portal\Controls\ObjectPanes\Invitations.ascx.cs:line 117

    To work around this I had to call ToArray() on the IEnumerable. Any thoughts?

  2. Chris
    Chris avatar
    40 posts
    Member since:
    Feb 2009

    Posted 21 Nov 2011 Link to this post

    Oh, and I'm using the following LINQ statement to create that IEnumberable:

    IEnumerable<Guid> tokenIds = rgInvitiations.SelectedItems.OfType<GridItem>()
        .Select(item => Guid.Parse(item.OwnerTableView.DataKeyValues[item.ItemIndex]["TokenId"].ToString()));
  3. DevCraft banner
  4. Thomas
    Admin
    Thomas avatar
    590 posts

    Posted 22 Nov 2011 Link to this post

    Hello Chris,

    I have found and fixed the issue; the needed bits will be included in the next build. I doubt however, that this worked before in an older build. The good news is, that using a .ToList() on the input parameters will solve the issue in your build; this will actually generate a List<Guid> that is an ICollection which we handled already correctly.

    I've updated your Telerik points.

    Greetings,
    Thomas
    the Telerik team
    Want to use Telerik OpenAccess with SQL Azure? Download the trial version today. 
Back to Top