目前Camstar开发主要分为两种,1、基于Designer的CLF编程;2、基于C#的程序编程。在Designer环境下的CLF可以通过(对象实例.字段)的方式快速访问数据,但Designer并不是完善的编程工具,不方便调试,没有语法校验等功能,开发效率较低。对于C#提供的各种类库,CLF同样难以调用。而C#有强大的生态环境,工具齐全,类库丰富。

为了能在C#环境下,更加便捷的访问操作Camstar对象数据。决定基于ORM框架构建Camstar的数据访问工具包。

网上可选的ORM框架很多,各有优劣,最终综合考虑下选择能支持懒加载以及配置对象关系的EF Core作为首选ORM框架。

一、项目地址

github:LicoCode/CamstarDbClient (github.com) 代码还在完善中。

git clone: https://github.com/LicoCode/CamstarDbClient.git

二、使用示例

支持Oracle与SqlServer数据库

1
2
3
4
5
6
7
8
9
10
11
//为CamstarDbClient配置数据库信息
DbConfiguration.Type = "Oracle"; //或SqlServer
DbConfiguration.DefaultConnection = "user id=OPCENTER;data source=localhost:1521/orclpdb;password=******;";

//查询工厂信息
using (var client = new DbClient())
{
Factory factory = client.GetNDOByName<Factory>("Test");
var factoryName = factory.Name;
var enterpriseName = factory.Enterprise.Name;
}

三、实体类示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
namespace CamstarDbClient.Entities
{
/// @Description A Factory often represent a physical or logical plant. A Factory can be any division, department, section, or group that is separated for accounting and reporting purposes. A Factory often represents a physical manufacturing building.
/// @author lichong
/// @date 2024/3/15
[Table("FACTORY")]
public class Factory: NamedDataObject
{
[Column("CDOTYPEID")]
public int? CDOTypeId { get; set; }

[Column("CHANGECOUNT")]
public int? ChangeCount { get; set; }

[Column("DESCRIPTION")]
public string? Description { get; set; }

[ForeignKey("ENTERPRISEID")]
public virtual Enterprise? Enterprise { get; set; }

[Key]
[Column("FACTORYID")]
public string? InstanceID { get; set; }

[Column("FACTORYNAME")]
public string? Name { get; set; }

[Column("NOTES")]
public string? Notes { get; set; }

[ForeignKey("PRINTQUEUEID")]
public virtual PrintQueue? PrintQueue { get; set; }

}

}

namespace CamstarDbClient.CamstarContext
{
public partial class CamstarDbContext : DbContext {
public DbSet<Factory> Factorys { get; set; }
}
public class FactoryEntityTypeConfiguration : IEntityTypeConfiguration<Factory>
{
public void Configure(EntityTypeBuilder<Factory> builder)
{

}
}

}