Files
SqlSugar/Src/Asp.NetCore2/SqlSeverTest/UserTestCases/UnitTest/Unitadfasdysdfa.cs
2025-07-15 16:39:12 +08:00

60 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
internal class Unitadfasdysdfa
{
public static void Init()
{
var db = NewUnitTest.Db;
db.CodeFirst.InitTables(new Type[] { typeof(TestSQLVariant) });
db.DbMaintenance.TruncateTable<TestSQLVariant>();
TestSQLVariant testSQLVariant = new TestSQLVariant();
testSQLVariant.Value = "-0.01~0.05";
testSQLVariant.Id = 1;
TestSQLVariant testSQLVariant1 = new TestSQLVariant();
testSQLVariant1.Value = "false";
testSQLVariant1.Id = 2;
TestSQLVariant testSQLVariant2 = new TestSQLVariant();
testSQLVariant2.Value = true;
db.Insertable(new List<TestSQLVariant>() { testSQLVariant, testSQLVariant1, testSQLVariant2 }).ExecuteCommand();
var list = db.Queryable<TestSQLVariant>().ToList();
}
public class TestSQLVariant
{
[SugarColumn(IsPrimaryKey = true)]
public int Id { get; set; }
[SugarColumn(ColumnDataType = "sql_variant", IsNullable = true, SqlParameterDbType = typeof(SqlVariantConvert))]
public object Value { get; set; }
}
//用例1
public class SqlVariantConvert : ISugarDataConverter
{
public SugarParameter ParameterConverter<T>(object value, int i)
{
var name = "@myp" + i;
return new SugarParameter(name, value) { CustomDbType=SqlDbType.Variant };
}
public T QueryConverter<T>(IDataRecord dr, int i)
{
var str = dr.GetValue(i) + "";
return (T)(object)str;
}
}
}
}