Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gbase8s回写主键问题 #1919

Closed
zxr6367587 opened this issue Nov 11, 2024 · 6 comments
Closed

gbase8s回写主键问题 #1919

zxr6367587 opened this issue Nov 11, 2024 · 6 comments

Comments

@zxr6367587
Copy link
Contributor

问题描述及重现代码:

使用gbase8时不会回写主键,使用ExecuteIdentity能返回ID

image

image

var fsql = new FreeSql.FreeSqlBuilder()
    .UseConnectionFactory(DataType.Custom, () => new GbsConnection("xxxxxxxxxxxx "))
    .UseMonitorCommand(cmd => Trace.WriteLine($"Sql:{cmd.CommandText}"))
    .UseQuoteSqlName(false)
    .Build();
 fsql.SetCustomAdapter(new GBSAdapter());
 fsql.SetDbProviderFactory(GbsFactory.Instance);

GBSAdapter
public override string InsertAfterGetIdentitySql => "select dbinfo('bigserial')   from dual";
// c# code

数据库版本

gbase8s

安装的Nuget包

3.2.833

.net framework/. net core? 及具体版本

.net 5

@zxr6367587
Copy link
Contributor Author

 /// <summary>
 /// 主键
 /// </summary>
 [Column(IsPrimary = true, IsIdentity = true)]
 public long ID { get; set; }

@zxr6367587
Copy link
Contributor Author

使用DataType.GBase类型的时候 会执行SELECT dbinfo('serial8') FROM dual 但是我们建库的时候使用的是bigserial 是否能使用datatype去动态修改查询语句

@zxr6367587
Copy link
Contributor Author

获取主键可以改为
SELECT DECODE( dbinfo('serial8'), 0, DECODE( dbinfo('bigserial'), 0, dbinfo('sqlca.sqlerrd1'), dbinfo('bigserial') ), dbinfo('serial8') ) FROM dual;

@2881099
Copy link
Collaborator

2881099 commented Nov 11, 2024

protected override long RawExecuteIdentity()

可以看 FreeSql.Provider.GBase 项目这个实现。

MapType = typeof(long) 也许可以帮到你

@zxr6367587
Copy link
Contributor Author

我使用UseConnectionString和FreeSql.Provider.GBase去链接GBase也是不回写主键 数据库自增列是bigserial 类型

@2881099
Copy link
Collaborator

2881099 commented Nov 12, 2024

protected override long RawExecuteIdentity()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants