mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-07 18:04:55 +08:00
Update Pgsql GetColumnInfosByTableName
This commit is contained in:
@@ -30,7 +30,24 @@ namespace OrmTest
|
|||||||
Db.Insertable(new List<UnitDateOfTime22> { new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
|
Db.Insertable(new List<UnitDateOfTime22> { new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
|
||||||
var list2 = Db.Queryable<UnitDateOfTime22>().ToList();
|
var list2 = Db.Queryable<UnitDateOfTime22>().ToList();
|
||||||
|
|
||||||
|
Db.CodeFirst.InitTables<UnitTestPk>();
|
||||||
|
Db.CodeFirst.InitTables<UnitTestPk>();
|
||||||
|
Db.CodeFirst.InitTables<UnitTestPk>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UnitTestPk
|
||||||
|
{
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey =true,IsIdentity =true)]
|
||||||
|
public int id { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true )]
|
||||||
|
public long id2 { get; set; }
|
||||||
|
[SqlSugar.SugarColumn(IsPrimaryKey = true )]
|
||||||
|
public Guid id3 { get; set; }
|
||||||
|
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[SqlSugar.SugarTable("UnitDateOfTime221")]
|
[SqlSugar.SugarTable("UnitDateOfTime221")]
|
||||||
public class UnitDateOfTime22
|
public class UnitDateOfTime22
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -394,6 +394,34 @@ namespace SqlSugar
|
|||||||
if (result == null || result.Count() == 0)
|
if (result == null || result.Count() == 0)
|
||||||
{
|
{
|
||||||
result = base.GetColumnInfosByTableName(tableName, isCache);
|
result = base.GetColumnInfosByTableName(tableName, isCache);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string sql = $@"select
|
||||||
|
kcu.column_name as key_column
|
||||||
|
from information_schema.table_constraints tco
|
||||||
|
join information_schema.key_column_usage kcu
|
||||||
|
on kcu.constraint_name = tco.constraint_name
|
||||||
|
and kcu.constraint_schema = tco.constraint_schema
|
||||||
|
and kcu.constraint_name = tco.constraint_name
|
||||||
|
where tco.constraint_type = 'PRIMARY KEY'
|
||||||
|
and kcu.table_schema='public' and
|
||||||
|
upper(kcu.table_name)=upper('{tableName}')";
|
||||||
|
var pkList = this.Context.Ado.SqlQuery<string>(sql);
|
||||||
|
if (pkList.Count >1)
|
||||||
|
{
|
||||||
|
foreach (var item in result)
|
||||||
|
{
|
||||||
|
if (pkList.Select(it=>it.ToUpper()).Contains(item.DbColumnName.ToUpper()))
|
||||||
|
{
|
||||||
|
item.IsPrimarykey = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user