mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 04:45:54 +08:00
PgSql Support array
This commit is contained in:
parent
92ee57967e
commit
8bc4e14b2d
53
Src/Asp.Net/PgSqlTest/Bugs/BugTest2.cs
Normal file
53
Src/Asp.Net/PgSqlTest/Bugs/BugTest2.cs
Normal file
@ -0,0 +1,53 @@
|
||||
//using SqlSugar;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.ComponentModel.DataAnnotations;
|
||||
//using System.Linq;
|
||||
//using System.Text;
|
||||
//using System.Threading.Tasks;
|
||||
|
||||
//namespace OrmTest.Test
|
||||
//{
|
||||
// public class BugTest
|
||||
// {
|
||||
// public static void Init()
|
||||
// {
|
||||
// SqlSugarClient Db = new SqlSugarClient(new ConnectionConfig()
|
||||
// {
|
||||
// ConnectionString = @"PORT=5433;DATABASE=x;HOST=localhost;PASSWORD=haosql;USER ID=postgres",
|
||||
// DbType = DbType.PostgreSQL,
|
||||
// IsAutoCloseConnection = true,
|
||||
// //MoreSettings = new ConnMoreSettings()
|
||||
// //{
|
||||
// // PgSqlIsAutoToLower = true //我们这里需要设置为false
|
||||
// //},
|
||||
// InitKeyType = InitKeyType.Attribute,
|
||||
// });
|
||||
// //调式代码 用来打印SQL
|
||||
// Db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
// {
|
||||
// // Debug.WriteLine(sql);
|
||||
// };
|
||||
|
||||
// Db.CodeFirst.InitTables(typeof(My12311x));
|
||||
|
||||
// var id= Db.Insertable(new My12311x { Menu_Id = new int[] { 1,2 } }).ExecuteReturnIdentity();
|
||||
// var list = Db.Queryable<My12311x>().InSingle(id);
|
||||
// list.Menu_Id = new int[] { 3};
|
||||
// Db.Updateable(list).ExecuteCommand();
|
||||
// list = Db.Queryable<My12311x>().InSingle(id);
|
||||
// }
|
||||
// }
|
||||
|
||||
// public class My12311x
|
||||
// {
|
||||
// [Key]
|
||||
// [Display(Name = "ID")]
|
||||
// [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
// public int Id { get; set; }
|
||||
|
||||
// [SugarColumn( ColumnDataType = "int []", IsArray =true)]
|
||||
// public int[] Menu_Id { get; set; }
|
||||
// }
|
||||
|
||||
//}
|
@ -61,6 +61,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Bugs\BugTest.cs" />
|
||||
<Compile Include="Bugs\BugTest2.cs" />
|
||||
<Compile Include="Demo\Demo0_SqlSugarClient.cs" />
|
||||
<Compile Include="Demo\Demo1_Queryable.cs" />
|
||||
<Compile Include="Demo\Demo2_Updateable.cs" />
|
||||
|
@ -64,6 +64,7 @@ namespace SqlSugar
|
||||
private static readonly MethodInfo getOtherNull = typeof(IDataRecordExtensions).GetMethod("GetOtherNull");
|
||||
private static readonly MethodInfo getOther = typeof(IDataRecordExtensions).GetMethod("GetOther");
|
||||
private static readonly MethodInfo getJson = typeof(IDataRecordExtensions).GetMethod("GetJson");
|
||||
private static readonly MethodInfo getArray = typeof(IDataRecordExtensions).GetMethod("GetArray");
|
||||
private static readonly MethodInfo getEntity = typeof(IDataRecordExtensions).GetMethod("GetEntity", new Type[] { typeof(SqlSugarProvider) });
|
||||
|
||||
private delegate T Load(IDataRecord dataRecord);
|
||||
@ -153,6 +154,22 @@ namespace SqlSugar
|
||||
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
||||
generator.MarkLabel(endIfLabel);
|
||||
}
|
||||
if (columnInfo.IsArray)
|
||||
{
|
||||
MethodInfo arrayMehtod = getArray.MakeGenericMethod(columnInfo.PropertyInfo.PropertyType);
|
||||
int i = DataRecord.GetOrdinal(fieldName);
|
||||
Label endIfLabel = generator.DefineLabel();
|
||||
generator.Emit(OpCodes.Ldarg_0);
|
||||
generator.Emit(OpCodes.Ldc_I4, i);
|
||||
generator.Emit(OpCodes.Callvirt, isDBNullMethod);
|
||||
generator.Emit(OpCodes.Brtrue, endIfLabel);
|
||||
generator.Emit(OpCodes.Ldloc, result);
|
||||
generator.Emit(OpCodes.Ldarg_0);
|
||||
generator.Emit(OpCodes.Ldc_I4, i);
|
||||
generator.Emit(OpCodes.Call, arrayMehtod);
|
||||
generator.Emit(OpCodes.Callvirt, columnInfo.PropertyInfo.GetSetMethod(true));
|
||||
generator.MarkLabel(endIfLabel);
|
||||
}
|
||||
}
|
||||
private void BindField(ILGenerator generator, LocalBuilder result, EntityColumnInfo columnInfo, string fieldName)
|
||||
{
|
||||
|
@ -248,6 +248,14 @@ namespace SqlSugar
|
||||
var value = obj.ObjToString();
|
||||
return new SerializeService().DeserializeObject<T>(value);
|
||||
}
|
||||
public static T GetArray<T>(this IDataReader dr, int i)
|
||||
{
|
||||
//pgsql
|
||||
var obj = dr.GetValue(i);
|
||||
if (obj == null)
|
||||
return default(T);
|
||||
return (T)obj;
|
||||
}
|
||||
|
||||
public static Nullable<T> GetConvertEnum_Null<T>(this IDataReader dr, int i) where T : struct
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user