mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-24 18:04:52 +08:00
Update Pgsql GetColumnInfosByTableName
This commit is contained in:
parent
b43b6181a5
commit
be84b3a157
@ -30,7 +30,24 @@ namespace OrmTest
|
||||
Db.Insertable(new List<UnitDateOfTime22> { new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now }, new UnitDateOfTime22() { DateTimeOffset1 = DateTimeOffset.Now } }).ExecuteCommand();
|
||||
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")]
|
||||
public class UnitDateOfTime22
|
||||
{
|
||||
|
@ -394,6 +394,34 @@ namespace SqlSugar
|
||||
if (result == null || result.Count() == 0)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user