dimanche 21 juin 2015

I've got a weird problem. I can use LINQ to get all of the rows in my database, but I can't get a List of the contents of one of the columns.

In the code below, "Derfus" is ends up being a List object and I can use the debugger to look at the list contents. "NewsItem" is the class name for the elements of the database. In each element of the Derfus list, the m_ItemId member variable is set to a non-zero value that I can see with the debugger. This is what I want, and I could use a loop to get these values. But I seem to have something wrong with my LINQ syntax on the second line because IdList, which is a List as expected, contains all zeros. IdList contains the right number of elements, the same as Derfus contains, but not the values that I expect.

var Derfus = ( from e in Context.Table select e ).ToList();
var IdList = ( from e in Context.Table select e.m_ItemId ).ToList();

These lines are one after another in the code. The table does contain m_ItemId as a column and it is a "long".

I am not sure what other code to show. Since the lines both compile, and lots of other functions work properly with this database, I don't know what else could be relevant. Here's the NewsItem definition:

public class NewsItem 
{
    [SQLite.PrimaryKey, SQLite.AutoIncrement, SQLite.Indexed]
    public int m_Id { get; set; }
    public long m_ItemId { get; set; }
    public String m_Title { get; set; }
    public String m_Subtitle { get; set; }
    ...
}

Note that I am using SQLite but it should not cause me problems like this, should it?

Aucun commentaire:

Enregistrer un commentaire