5
votes

I'm developing a Windows Store App with sqlite as database. I'm using SQLite for Windows Runtime and sqlite-net. Trying to get a list of Guid from a table, but only getting empty guids in the list ({00000000-0000-0000-0000-000000000000}). However when querying only for one guid it works as it should be.

My code is the following:

async void SyncSurveys()
    {
        SQLiteConnection _db = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "SurveyDB"));

        var localSurveys = (from s in _db.Table<Survey>()
            select s.SurveyGuid).ToList();

        ...
    }

I've tried the query in the following format also, but it is neither works:

var localSurveys = _db.Table<Survey>().Select(s => s.SurveyGuid).ToList();

But if I'm using the following query, to get only one guid just for debug purpose it works well:

var localSurvey = db.Table<Survey>().FirstOrDefault().SurveyGuid;

In the not working scenario the list's count matches the table's rowcount. Does anyone have any idea why this isn't working with the list version?

2
Try using a Parse method, e.g. _db.Table<Survey>().Select(s => Guid.Parse(s.SurveyGuid)).ToList();. Not sure what's the data type of SurveyGuid, is it string in a database? This would usually happen when the code calls new Guid() instead of Guid.NewGuid() or Guid.Parse* - oleksii
SurveyGuid's type is System.Guid, the table generated with the sqlite-net, but as I know in sqlite database isn't a thing called datatype, your datatype can by anything, like ChickenSoup or whatever. Your solution won't work, because SurveyGuid is a Guid, but Guid.Parse() expects string. - Ferenc Balogh
can you post the table structure to sqlfiddle.com ? - Baljeetsingh

2 Answers

2
votes

This isn't an answer, but it might put you down the right path. I noticed there is an option that can be added to a connection string that sets if GUIDS are stored in binary or not

Data Source=c:\mydb.db;Version=3;BinaryGUID=False;

More info https://www.connectionstrings.com/sqlite/

-1
votes

I think the problem should be the basic script commands are properly written. It may be a bug database.