zoukankan      html  css  js  c++  java
  • 【C# SQLite】SQLite 问题集(一)

    SQLite DateTime比较
    SELECT * FROM table WHERE 
        strftime('%s', date) BETWEEN strftime('%s', start_date) AND strftime('%s', end_date)
    linq for sqlite的使用方法(C#)

    1. 添加引用到工程

    System.Data.SQLite

    System.Data.SQLite.Linq

    2. 修改app.config, 如下:

    <?xml version="1.0"?>
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku = ".NETFramework,Version=v4.0"/>
        <supportedRuntime version="v2.0.50727"/>
      </startup>
    </configuration>

    3. 建立与sqlite表对应的实体类:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.Linq.Mapping;
    
    namespace linq_test
    {
        [Table(Name = "A")]
        public class A
        {
            [Column(Name = "col_1")]
            public string Col_1 { get; set; }
        }
     
    }

    4. 通过DataContext, 编写查询linq  to sql

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SQLite;
    using System.Data.Linq;
    
    namespace linq_test
    {
        class Program
        {
            static void Main(string[] args)
            {
                var ctx = new DataContext(new SQLiteConnection( "data source=d:\test.db"));
                Table<A> a = ctx.GetTable<A>();
                var query = from p in a select p;
                foreach (var item in query)
                {
                    System.Console.WriteLine("ID:{0}", item.Col_1);
                }
    
                System.Console.ReadKey();
            }
        }
    }
  • 相关阅读:
    一个简单的MVVM雏形
    sass学习笔记1
    col标签的相关实验
    背景半透明rgba最佳实践
    angular性能优化心得
    环视非捕获分组
    5月23日Google就宣布了Chrome 36 beta
    浏览器 user-agent 字符串的故事
    迷你MVVM框架 avalonjs 沉思录 第3节 动态模板
    迷你MVVM框架 avalonjs 1.3.1发布
  • 原文地址:https://www.cnblogs.com/GothicLolita/p/13600202.html
Copyright © 2011-2022 走看看