locked
SQLite Linq to SQL novice question

    Question

  • Hello!

    I have a simple question about SQLite.

    I have small sample DB.

    CREATE TABLE table1 (
        name    VARCHAR,
        surname VARCHAR
    );


    I inserted 3 records via SQLite manager to this DB.

    Now I'd like to read and this DB in c#.

    public class SampleDB : DataContext
        {
            public Table<Peoples> peoples;
            public SampleDB(string connection) : base(connection) { }
        }
     
     
        [Table(Name = "table1")]
        public class Peoples
        {
            [Column(Name = "Name")]
            public string Name { get; set; }
            [Column(Name = "Surname")]
            public string Surname { get; set; }
        }
        
        class Program
        {
            static void Main(string[] args)
            {
                var connection = new SQLiteConnection(@"Data Source=d:\via\simple.sqlite");
                var context = new DataContext(connection);
                var peoples = context.GetTable<Peoples>();
                
                SampleDB db = new SampleDB(@"Data Source=d:\via\simple.sqlite");
                var query = from q in db.peoples
                            where q.Name == "Alex"
                            select q;           
                
            }
        }

    Variable "Peoples" is working good. But "query" is not working. What's wrong with this code?

    Thanks.

    Thursday, March 12, 2015 10:37 AM

Answers

All replies

  • I think you're supposed to use a regular SQL query with SQLite.  I'm not a SQLite expert so I'm not sure. 

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, March 12, 2015 6:23 PM
    Moderator
  • it seems you have not queried yet, try query.ToList method to complete the query.

    Friday, March 13, 2015 5:44 AM