mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
- 修复 postgresql 12 移除 pg_attrdef.adsrc 列,导致 CodeFirst 方法失败的 bug;
- 增加 Aop.ConfigEntity 属性 ModifyIndexResult 现实 IndexAttribute 的设置;
This commit is contained in:
parent
0485a22a5c
commit
615023f012
@ -351,7 +351,7 @@ namespace FreeSql.Tests.PostgreSQL
|
||||
[Table(Name = "tb_alltype")]
|
||||
class TableAllType
|
||||
{
|
||||
[Column(IsIdentity = true, IsPrimary = true)]
|
||||
[Column(IsPrimary = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
public bool testFieldBool { get; set; }
|
||||
|
@ -2185,6 +2185,11 @@
|
||||
实体配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityEventArgs.ModifyIndexResult">
|
||||
<summary>
|
||||
索引配置
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:FreeSql.Aop.ConfigEntityPropertyEventArgs.EntityType">
|
||||
<summary>
|
||||
实体类型
|
||||
|
@ -115,6 +115,7 @@ namespace FreeSql.Aop
|
||||
{
|
||||
this.EntityType = entityType;
|
||||
this.ModifyResult = new TableAttribute();
|
||||
this.ModifyIndexResult = new List<IndexAttribute>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -125,6 +126,10 @@ namespace FreeSql.Aop
|
||||
/// 实体配置
|
||||
/// </summary>
|
||||
public TableAttribute ModifyResult { get; }
|
||||
/// <summary>
|
||||
/// 索引配置
|
||||
/// </summary>
|
||||
public List<IndexAttribute> ModifyIndexResult { get; }
|
||||
}
|
||||
public class ConfigEntityPropertyEventArgs : EventArgs
|
||||
{
|
||||
|
@ -87,7 +87,6 @@ namespace FreeSql.Internal
|
||||
if (!string.IsNullOrEmpty(trytb.OldName)) attr.OldName = trytb.OldName;
|
||||
if (!string.IsNullOrEmpty(trytb.SelectFilter)) attr.SelectFilter = trytb.SelectFilter;
|
||||
if (trytb._DisableSyncStructure != null) attr._DisableSyncStructure = trytb.DisableSyncStructure;
|
||||
|
||||
}
|
||||
var attrs = type.GetCustomAttributes(typeof(TableAttribute), false);
|
||||
foreach (var tryattrobj in attrs)
|
||||
@ -190,12 +189,24 @@ namespace FreeSql.Internal
|
||||
}
|
||||
public IndexAttribute[] GetEntityIndexAttribute(Type type)
|
||||
{
|
||||
var ret = new Dictionary<string, IndexAttribute>(); ;
|
||||
var ret = new Dictionary<string, IndexAttribute>();
|
||||
if (_orm.Aop.ConfigEntity != null)
|
||||
{
|
||||
var aope = new Aop.ConfigEntityEventArgs(type);
|
||||
_orm.Aop.ConfigEntity(_orm, aope);
|
||||
foreach (var idxattr in aope.ModifyIndexResult)
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
}
|
||||
}
|
||||
if (dicConfigEntity.TryGetValue(type, out var trytb))
|
||||
{
|
||||
foreach (var idxattr in trytb._indexs.Values)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
}
|
||||
}
|
||||
@ -204,11 +215,12 @@ namespace FreeSql.Internal
|
||||
{
|
||||
var idxattr = tryattrobj as IndexAttribute;
|
||||
if (idxattr == null) continue;
|
||||
if (string.IsNullOrEmpty(idxattr.Name)) continue;
|
||||
if (string.IsNullOrEmpty(idxattr.Fields)) continue;
|
||||
if (!string.IsNullOrEmpty(idxattr.Name) && !string.IsNullOrEmpty(idxattr.Fields))
|
||||
{
|
||||
if (ret.ContainsKey(idxattr.Name)) ret.Remove(idxattr.Name);
|
||||
ret.Add(idxattr.Name, new IndexAttribute(idxattr.Name, idxattr.Fields) { _IsUnique = idxattr._IsUnique });
|
||||
}
|
||||
}
|
||||
return ret.Values.ToArray();
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,8 @@ t.typname,
|
||||
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
|
||||
case when t.typelem > 0 and t.typinput::varchar = 'array_in' then t2.typname else t.typname end,
|
||||
case when a.attnotnull then '0' else '1' end as is_nullable,
|
||||
e.adsrc,
|
||||
coalesce((select 1 from pg_sequences where sequencename = {0} || '_' || {1} || '_' || a.attname || '_sequence_name' limit 1),0) is_identity,
|
||||
--e.adsrc,
|
||||
a.attndims,
|
||||
d.description as comment
|
||||
from pg_class c
|
||||
@ -201,7 +202,7 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
|
||||
sqlType = string.Concat(sqlType),
|
||||
max_length = long.Parse(string.Concat(a[2])),
|
||||
is_nullable = string.Concat(a[4]) == "1",
|
||||
is_identity = string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
|
||||
is_identity = string.Concat(a[5]) == "1", //string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
|
||||
attndims,
|
||||
comment = string.Concat(a[7])
|
||||
};
|
||||
|
@ -208,8 +208,8 @@ t.typname,
|
||||
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
|
||||
case when t.typelem = 0 then t.typname else t2.typname end,
|
||||
case when a.attnotnull then 0 else 1 end as is_nullable,
|
||||
e.adsrc as is_identity,
|
||||
--case when e.adsrc = 'nextval(''' || case when ns.nspname = 'public' then '' else ns.nspname || '.' end || c.relname || '_' || a.attname || '_seq''::regclass)' then 1 else 0 end as is_identity,
|
||||
coalesce((select 1 from pg_sequences where sequencename = {0} || '_' || {1} || '_' || a.attname || '_sequence_name' limit 1),0) is_identity,
|
||||
--e.adsrc as is_identity,
|
||||
d.description as comment,
|
||||
a.attndims,
|
||||
case when t.typelem = 0 then t.typtype else t2.typtype end,
|
||||
@ -235,7 +235,7 @@ where {loc8.ToString().Replace("a.table_name", "ns.nspname || '.' || c.relname")
|
||||
var max_length = int.Parse(string.Concat(row[3]));
|
||||
var sqlType = string.Concat(row[4]);
|
||||
var is_nullable = string.Concat(row[5]) == "1";
|
||||
var is_identity = string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
|
||||
var is_identity = string.Concat(row[6]) == "1"; //string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
|
||||
var comment = string.Concat(row[7]);
|
||||
int attndims = int.Parse(string.Concat(row[8]));
|
||||
string typtype = string.Concat(row[9]);
|
||||
|
@ -207,7 +207,8 @@ t.typname,
|
||||
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
|
||||
case when t.typelem > 0 and t.typinput::varchar = 'array_in' then t2.typname else t.typname end,
|
||||
case when a.attnotnull then '0' else '1' end as is_nullable,
|
||||
e.adsrc,
|
||||
coalesce((select 1 from pg_sequences where sequencename = {0} || '_' || {1} || '_' || a.attname || '_sequence_name' limit 1),0) is_identity,
|
||||
--e.adsrc,
|
||||
a.attndims,
|
||||
d.description as comment
|
||||
from pg_class c
|
||||
@ -243,7 +244,7 @@ where ns.nspname = {0} and c.relname = {1}", tboldname ?? tbname);
|
||||
sqlType = string.Concat(sqlType),
|
||||
max_length = long.Parse(string.Concat(a[2])),
|
||||
is_nullable = string.Concat(a[4]) == "1",
|
||||
is_identity = string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
|
||||
is_identity = string.Concat(a[5]) == "1", //string.Concat(a[5]).StartsWith(@"nextval('") && string.Concat(a[5]).EndsWith(@"'::regclass)"),
|
||||
attndims,
|
||||
comment = string.Concat(a[7])
|
||||
};
|
||||
|
@ -319,8 +319,8 @@ t.typname,
|
||||
case when a.atttypmod > 0 and a.atttypmod < 32767 then a.atttypmod - 4 else a.attlen end len,
|
||||
case when t.typelem = 0 then t.typname else t2.typname end,
|
||||
case when a.attnotnull then 0 else 1 end as is_nullable,
|
||||
e.adsrc as is_identity,
|
||||
--case when e.adsrc = 'nextval(''' || case when ns.nspname = 'public' then '' else ns.nspname || '.' end || c.relname || '_' || a.attname || '_seq''::regclass)' then 1 else 0 end as is_identity,
|
||||
coalesce((select 1 from pg_sequences where sequencename = {0} || '_' || {1} || '_' || a.attname || '_sequence_name' limit 1),0) is_identity,
|
||||
--e.adsrc as is_identity,
|
||||
d.description as comment,
|
||||
a.attndims,
|
||||
case when t.typelem = 0 then t.typtype else t2.typtype end,
|
||||
@ -346,7 +346,7 @@ where {loc8.ToString().Replace("a.table_name", "ns.nspname || '.' || c.relname")
|
||||
var max_length = int.Parse(string.Concat(row[3]));
|
||||
var sqlType = string.Concat(row[4]);
|
||||
var is_nullable = string.Concat(row[5]) == "1";
|
||||
var is_identity = string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
|
||||
var is_identity = string.Concat(row[6]) == "1"; //string.Concat(row[6]).StartsWith(@"nextval('") && string.Concat(row[6]).EndsWith(@"'::regclass)");
|
||||
var comment = string.Concat(row[7]);
|
||||
int attndims = int.Parse(string.Concat(row[8]));
|
||||
string typtype = string.Concat(row[9]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user