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();
            }
        }
    }
  • 相关阅读:
    socat + kata + cgroup
    2018-8-10-卷积神经网络全面解析
    2019-8-31-PowerShell-通过-WMI-获取系统服务
    2019-8-31-PowerShell-通过-WMI-获取系统服务
    2018-2-13-不使用数据结构反转栈
    统计难题
    Keywords Search
    [JSOI2008]最大数
    Android(java)学习笔记1:多线程的引入
    欢迎使用CSDN-markdown编辑器
  • 原文地址:https://www.cnblogs.com/GothicLolita/p/13600202.html
Copyright © 2011-2022 走看看