当前位置: 首页 > 工具软件 > linq2db > 使用案例 >

linq2db.mysql_Linq to SQlite简单示例(linq2db版)

连俊智
2023-12-01

using LinqToDB;

using System;

using System.Linq;

namespace ConsoleApp1

{

class Program

{

static void Main(string[] args)

{

using (var db = new TestDB())

{

//Insert

db.Insert(new UserTB() { Name = "张三", Age = 20 });

var id = db.InsertWithInt32Identity(new UserTB() { Name = "李四", Age = 30 });

//Update

var user1 = db.UserTbs.FirstOrDefault();

user1.Name += "new";

db.Update(user1);

//Delete

var user2 = db.UserTbs.OrderByDescending(item => item.Id).FirstOrDefault(); //不支持方法LastOrDefault

db.Delete(user2);

//db.UserTbs.Where(item => item.Id == id).Delete();

//Select

var users = db.UserTbs.ToList();

foreach (var item in users)

{

Console.WriteLine("{0},{1},{2}", item.Id, item.Name, item.Age);

}

}

Console.ReadLine();

}

}

}

 类似资料: