SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6 KiB

2 years ago
using SqlSugar;
using System;
6 years ago
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public partial class NewUnitTest
{
public static void Json()
{
6 years ago
Db.CodeFirst.InitTables<UnitJsonTest>();
Db.DbMaintenance.TruncateTable<UnitJsonTest>();
Db.Insertable(new UnitJsonTest() { Order = new Order { Id = 1, Name = "order1" } }).ExecuteCommand();
var list = Db.Queryable<UnitJsonTest>().ToList();
6 years ago
UValidate.Check("order1", list.First().Order.Name, "Json");
6 years ago
Db.Updateable(new UnitJsonTest() { Id = 1, Order = new Order { Id = 2, Name = "order2" } }).ExecuteCommand();
2 years ago
var json = Db.Queryable<UnitJsonTest>().Select(it => SqlFunc.JsonField(it.Order, "Name")).ToList();
4 years ago
list = Db.Queryable<UnitJsonTest>().ToList();
6 years ago
UValidate.Check("order2", list.First().Order.Name, "Json");
4 years ago
Db.Updateable<UnitJsonTest>().SetColumns(x => new UnitJsonTest { Order = new Order { Id = 2, Name = "order3" } }).Where(x => x.Id == 1).ExecuteCommand();
list = Db.Queryable<UnitJsonTest>().ToList();
UValidate.Check("order3", list.First().Order.Name, "Json");
6 years ago
var list2 = Db.Queryable<UnitJsonTest>().ToList();
6 years ago
}
}
6 years ago
public class UnitJsonTest
6 years ago
{
[SqlSugar.SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; }
6 years ago
[SqlSugar.SugarColumn(ColumnDataType = "varchar(4000)", IsJson = true)]
6 years ago
public Order Order { get; set; }
}
}