返回首页

gbase数据、南大通用产品文档:GBase8aCodeFirst 模式

更新日期:2024年09月11日

通过编写代码直接操作数据表!需要在App.config 中配置相应的连接串:





connectionString="server=192.168.5.4;User
Id=sysdba;password=1;Initial Catalog=BlogTest;
Persist Security Info=True;"
providerName="GBase.Data.GBaseClient"
/>



GBase 8a 程序员手册ADO.NET 篇


- 108 -

南大通用数据技术股份有限公司
C#代码示例:
namespace EF_codefirst
{

public class Blog
{
public int BlogId { get; set; }
public string Name { get; set; }

public virtual List Posts { get; set; }
}

public class Post
{
public int PostId { get; set; }
public string Title { get; set; }
public string Content { get; set; }

public int BlogId { get; set; }
public virtual Blog Blog { get; set; }
}

public class BloggingContext : DbContext
{
public DbSet Blogs { get; set; }
public DbSet Posts { get; set; }
}

class Program
{

static void Main(string[] args)



GBase 8a 程序员手册ADO.NET 篇
南大通用数据技术股份有限公司

- 109 -
{
InsertData();
QueryData();
}

///


/// 插入数据
///

public static void InsertData()
{
try
{
using (var db = new BloggingContext())
{
//Create and save a new Blog
Console.Write("Enter a name for a new Blog:");
var name = Console.ReadLine();

var blog = new Blog { Name = name };
db.Blogs.Add(blog);
db.SaveChanges();
}
}
catch (System.Exception ex)
{
throw ex.InnerException;
}

QueryData();
}

///

GBase 8a 程序员手册ADO.NET 篇


- 110 -

南大通用数据技术股份有限公司
/// 查询数据
///

public static void QueryData()
{
try
{
using (var db = new BloggingContext())
{
//Display all Blogs from the DB
var query = from b in db.Blogs
orderby b.Name
select b;

Console.WriteLine("All blogs in the database:");
foreach (var item in query)
{
Console.WriteLine(item.Name);
}

Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
catch (System.Exception ex)
{
throw;
}

}

}




GBase 8a 程序员手册ADO.NET 篇
南大通用数据技术股份有限公司

- 111 -

查看数据库用户
通过PG_USER 可以查看数据库中所有用户的列表,还可以查看用户ID(USESYSID)
和用户权限。
postgres=# SELECT * FROM pg_user;
usename | usesysid | usecreatedb | usesuper | usecatupd | userepl |
passwd
|
valbegin | valuntil |
respool
| parent | spacelimit | useconfig | nodegroup
| tempspacelimit | spillspacelimit | usemonitoradmin | useoperatoradmin | usepo
licyadmin
---------+----------+-------------+----------+-----------+---------+---------
-+-
---------+----------+--------------+--------+------------+-----------+-------
---
-+----------------+-----------------+-----------------+------------------+---
---
----------
gbase
|
10 | t
| t
| t
| t
| ******** |
|
| default_pool |
0 |
|
|
|
|
| t
| t
| t
jack
|
16549 | f
| f
| f
| f
| ******** |
|
| default_pool |
0 |
|
|
|
|
| f
| f
| f
(2 rows)

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
31

SQLDataSources 列出数据源名称。
下表描述了 SQLDataSources 的 SQLSTATE 和错误值。
SQLSTATE
错误值
错误消息
01000
-11001
General warning
01004
-11003
Data truncated
S1000
-11060
General error
S1001
-11061
Memory-allocation failure
S1090
-11071
Invalid string or buffer length
S1103
-11083
Direction option out of range