From 26abd9ea9a37d721ff7d3c536a5e08e1ce626137 Mon Sep 17 00:00:00 2001
From: dailyccc <963922242@qq.com>
Date: Sat, 3 Dec 2022 11:16:12 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0ClickHouse=20CodeFirst?=
 =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
 .../ClickHouse/ClickHouseTest2.cs             |  27 ++
 .../ClickHouse/CollectDataEntity2.cs          | 237 ++++++++++++++++++
 2 files changed, 264 insertions(+)
 create mode 100644 FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs
 create mode 100644 FreeSql.Tests/FreeSql.Tests/ClickHouse/CollectDataEntity2.cs
diff --git a/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs b/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs
new file mode 100644
index 00000000..5b21741d
--- /dev/null
+++ b/FreeSql.Tests/FreeSql.Tests/ClickHouse/ClickHouseTest2.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using System.Text;
+using System.Linq;
+using System.Collections;
+using System.Diagnostics;
+using System.ComponentModel.DataAnnotations;
+using FreeSql.DataAnnotations;
+using Xunit;
+
+namespace FreeSql.Tests.ClickHouse
+{
+    public class ClickHouseTest2
+    {
+        private static IFreeSql fsql = new FreeSqlBuilder().UseConnectionString(DataType.ClickHouse,
+                "Host=127.0.0.1;Port=8123;Database=test;Compress=True;Min Pool Size=1")
+            .UseMonitorCommand(cmd => Console.WriteLine($"线程:{cmd.CommandText}\r\n"))
+            .UseNoneCommandParameter(true)
+            .Build();
+        [Fact]
+        public void CodeFirst()
+        {
+            fsql.CodeFirst.SyncStructure(typeof(CollectDataEntityUpdate01));
+        }
+    }
+}
\ No newline at end of file
diff --git a/FreeSql.Tests/FreeSql.Tests/ClickHouse/CollectDataEntity2.cs b/FreeSql.Tests/FreeSql.Tests/ClickHouse/CollectDataEntity2.cs
new file mode 100644
index 00000000..112e3620
--- /dev/null
+++ b/FreeSql.Tests/FreeSql.Tests/ClickHouse/CollectDataEntity2.cs
@@ -0,0 +1,237 @@
+using FreeSql.DataAnnotations;
+using Newtonsoft.Json;
+using System;
+using System.ComponentModel;
+
+namespace FreeSql.Tests.ClickHouse
+{
+    /// 
+    /// 实时数据
+    /// 
+    [Index("idx_{tablename}_01", nameof(Guid), true)]
+    [Index("idx_{tablename}_02", nameof(TenantId), true)]
+    //复合索引
+    [Index("idx_{tablename}_03", $"{nameof(CreatedUserId)},{nameof(Version)}", false)]
+    [Table(OldName = "CollectDataEntityUpdate")]
+    public partial class CollectDataEntityUpdate01
+    {
+        /// 
+        /// Guid
+        /// 
+        [Column(StringLength = 50)]
+        public string Guid
+        {
+            get; set;
+        }
+
+        /// 
+        /// 租户Id
+        /// 
+        [Description("租户Id")]
+        [Column(CanUpdate = false)]
+        public virtual long? TenantId
+        {
+            get; set;
+        }
+
+        /// 
+        /// 版本
+        /// 
+        [Description("版本")]
+        [Column(IsVersion = false)]
+        public long Version
+        {
+            get; set;
+        }
+
+        /// 
+        /// 是否删除
+        /// 
+        [Description("是否删除")]
+        [Column()]
+        public bool IsDeleted { get; set; } = false;
+
+        /// 
+        /// 创建者Id
+        /// 
+        [Description("创建者Id")]
+        [Column(CanUpdate = false)]
+        public long? CreatedUserId
+        {
+            get; set;
+        }
+
+        /// 
+        /// 创建者
+        /// 
+        [Description("创建者")]
+        [Column(CanUpdate = false, StringLength = 50, OldName = "CreatedUserNameUpdate")]
+        public string CreatedUserNameUpdate01
+        {
+            get; set;
+        }
+
+        /// 
+        /// 创建时间
+        /// 
+        [Description("创建时间")]
+        [Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
+        public DateTime? CreatedTime
+        {
+            get; set;
+        }
+
+        /// 
+        /// 修改者Id
+        /// 
+        [Description("修改者Id")]
+        [Column(CanInsert = false)]
+        public long? ModifiedUserId
+        {
+            get; set;
+        }
+
+        /// 
+        /// 修改者
+        /// 
+        [Description("修改者")]
+        [Column(CanInsert = false, StringLength = 50)]
+        public string ModifiedUserName
+        {
+            get; set;
+        }
+
+        /// 
+        /// 修改时间
+        /// 
+        [Description("修改时间")]
+        [Column(CanInsert = false, ServerTime = DateTimeKind.Local)]
+        public DateTime? ModifiedTime
+        {
+            get; set;
+        }
+        /// 
+        /// 数据标识
+        /// 
+        [Description("数据标识")]
+        [Column(CanInsert = false, StringLength = 2)]
+        public string DataFlag
+        {
+            get; set;
+        }
+        /// 
+        /// 主键Id
+        /// 
+        [Description("主键Id")]
+        [Column(Position = 1, IsPrimary = true)]
+        public long Id
+        {
+            get; set;
+        }
+        /// 
+        /// 设备编号
+        /// 
+        [Column(StringLength = 50)]
+        public string EquipmentCode
+        {
+            get; set;
+        }
+
+        /// 
+        /// 数据编号,如为空使用默认数据
+        /// 
+        [Column(StringLength = 50)]
+        public string PropertyCode
+        {
+            get; set;
+        }
+        /// 
+        ///  数据名称,如为空使用默认数据
+        /// 
+        [Column(StringLength = 50)]
+        public string PropertyName
+        {
+            get; set;
+        }
+
+        /// 
+        /// 数值或状态是否变更
+        /// 
+        public bool IsValueOrStateChanged
+        {
+            get; set;
+        }
+
+        /// 
+        /// 采集数值
+        /// 
+        [Column(StringLength = 18)]
+        public decimal? NumericValue
+        {
+            get; set;
+        }
+
+        /// 
+        /// 备注
+        /// 
+        [Column(StringLength = 200)]
+        public string Remark
+        {
+            get; set;
+        }
+
+        /// 
+        /// 服务标记
+        /// 
+        [Column(StringLength = 20)]
+        public string ServiceFlag
+        {
+            get; set;
+        }
+
+        /// 
+        /// 状态
+        /// 
+        [Column(StringLength = 50)]
+        public string StrState
+        {
+            get; set;
+        }
+
+        /// 
+        /// 文本数值
+        /// 
+        [Column(StringLength = 50)]
+        public string StrValue
+        {
+            get; set;
+        }
+
+        /// 
+        /// 单位
+        /// 
+        [Column(StringLength = 10)]
+        public string UnitStr
+        {
+            get; set;
+        }
+
+        /// 
+        /// 采集时间
+        /// 
+        public DateTime CollectTime
+        {
+            get; set;
+        }
+
+
+        public string FieldKey
+        {
+            get
+            {
+                return EquipmentCode + "_" + PropertyCode;
+            }
+        }
+    }
+
+}
\ No newline at end of file