Page 1 of 1

Cannot make WHERE IN clause working properly in LINQ to Entities

Posted: Fri 16 Jun 2017 05:41
by bairog
Hello.
I'm trying to select items from database with List in a “WHERE” condition.
Assume we have the following entities:

Code: Select all

public class Message
    {
        public Guid Id { get; set; }
        public String Text { get; set; }
        public bool IsPrivate { get; set; }
        public Guid UserId { get; set; }        
    }

    public class User
    {
        public Guid Id { get; set; }
        public String Name { get; set; }
        public int Age { get; set; }       
    } 
I want to get messages posted by two users. I've tried the following code:

Code: Select all

messages = ActiveContext.Messages.Where(m => listOfUserIds.Contains(m.UserId)).ToList();
That doesn't work (0 items returned while 2 exists in database);
I've tried even the following approach:

Code: Select all

var guid1 = listOfUserIds[0];
var query = ActiveContext.Messages.Where(m => m.UserId.Equals(guid1));
var guid2 = listOfUserIds[1];
query = query.Concat(ActiveContext.Messages.Where(m => m.UserId.Equals(guid2)));
messages = query.ToList();
It does't work also.
What's wrong with my code?
I use dotConnect for SQLite 5.3.583.

Sample project I've uploaded here
Click AddUsersAndMessages() button first to create database (on disk D) and then click ReadMessages() button (it uses all code above).

Re: Cannot make WHERE IN clause working properly in LINQ to Entities

Posted: Fri 16 Jun 2017 15:54
by Shalex
Thank you for your report. We have reproduced the issue and are investigating it. We will notify you about the result.

Re: Cannot make WHERE IN clause working properly in LINQ to Entities

Posted: Thu 22 Jun 2017 10:30
by Pinturiccio
We have fixed the bug with SQL generation of literals for System.Guid values. We will notify when the corresponding build of dotConnect for SQLite is available for download.

Re: Cannot make WHERE IN clause working properly in LINQ to Entities

Posted: Fri 23 Jun 2017 05:07
by bairog
Pinturiccio wrote:We have fixed the bug with SQL generation of literals for System.Guid values
So the problem is specific for .Contains(System.Guid)?
The bug doesn't affect other types - for example with .Contains(System.Int32) or .Contains(System.String)?

Re: Cannot make WHERE IN clause working properly in LINQ to Entities

Posted: Fri 23 Jun 2017 16:08
by Pinturiccio
bairog wrote:So the problem is specific for .Contains(System.Guid)?
Yes, it is. This issue is already fixed, and the new build of dotConnect for SQLite with the fix is available for download. Please try the latest build and tell us about the results.
bairog wrote:The bug doesn't affect other types - for example with .Contains(System.Int32) or .Contains(System.String)?
Yes, that’s true. Contains(System.Int32) or .Contains(System.String) works correctly.

New build of dotConnect for SQLite 5.9.913 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/sqlite/download.html (trial version) or from Customer Portal (for users with valid subscription only).
For more information, please refer to viewtopic.php?t=35588

Re: Cannot make WHERE IN clause working properly in LINQ to Entities

Posted: Mon 26 Jun 2017 18:26
by bairog
Pinturiccio wrote:This issue is already fixed, and the new build of dotConnect for SQLite with the fix is available for download. Please try the latest build and tell us about the results.
I confirm that with latest SQLite 5.9.931 my code works correctly.
Thanks.