首页 > 数据库技术 > 详细

【C# SQLite】SQLite 问题集(一)

时间:2020-09-02 11:39:45      阅读:60      评论:0      收藏:0      [点我收藏+]
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();
        }
    }
}

 

【C# SQLite】SQLite 问题集(一)

原文:https://www.cnblogs.com/GothicLolita/p/13600202.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!