diff --git a/Docs/codefirst.md b/Docs/codefirst.md
index 0bafd459..46ef96a8 100644
--- a/Docs/codefirst.md
+++ b/Docs/codefirst.md
@@ -1,18 +1,10 @@
# CodeFirst
-### 支持的类型
+| 数据库 | 支持的类型类型 |
+| - | - |
+| MySql | bool, sbyte, short, int, long, byte, ushort, uint, ulong, double, float, decimal, Guid, TimeSpan, DateTime
bool?, sbyte?, short?, int?, long?, byte?, ushort?, uint?, ulong?, double?, float?, decimal?, Guid?, TimeSpan?, DateTime?
byte[], string, Enum & FlagsEnum
MygisPoint, MygisLineString, MygisPolygon, MygisMultiPoint, MygisMultiLineString, MygisMultiPolygon |
+| SqlServer | bool, sbyte, short, int, long, byte, ushort, uint, ulong, double, float, decimal, Guid, TimeSpan, DateTime, DateTimeOffset
bool?, sbyte?, short?, int?, long?, byte?, ushort?, uint?, ulong?, double?, float?, decimal?, Guid?, TimeSpan?, DateTime?, DateTimeOffset?
byte[], string, Enum & FlagsEnum |
-bool, byte, short, int, long, byte, ushort, uint, ulong, double, float, decimal, int, Guid
-
-bool?, byte?, short?, int?, long?, byte?, ushort?, uint?, ulong?, double?, float?, decimal?, int?, Guid?
-
-TimeSpan, DateTime
-
-TimeSpan?, DateTime?
-
-byte[], string
-
-MygisPoint, MygisLineString, MygisPolygon, MygisMultiPoint, MygisMultiLineString, MygisMultiPolygon
```csharp
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
diff --git a/FreeSql.Tests/Class1.cs b/FreeSql.Tests/Class1.cs
index da9da817..5f282702 100644
--- a/FreeSql.Tests/Class1.cs
+++ b/FreeSql.Tests/Class1.cs
@@ -1,126 +1 @@
-
-//using System;
-//using System.Collections;
-//using System.Collections.Generic;
-//using System.Linq;
-//using System.Text;
-//using System.Text.RegularExpressions;
-//using FreeSql;
-//using FreeSql.DatabaseModel;
-
-////namespace TplDynamicCodeGenerate {
-//public class TplDynamicCodeGenerate_view1 : FreeSql.Generator.TemplateEngin.ITemplateOutput {
-// public FreeSql.Generator.TemplateEngin.TemplateReturnInfo OuTpUt(StringBuilder tOuTpUt, IDictionary oPtIoNs, string rEfErErFiLeNaMe, FreeSql.Generator.TemplateEngin tEmPlAtEsEnDeR) {
-// FreeSql.Generator.TemplateEngin.TemplateReturnInfo rTn = tOuTpUt == null ?
-// new FreeSql.Generator.TemplateEngin.TemplateReturnInfo { Sb = (tOuTpUt = new StringBuilder()), Blocks = new Dictionary() } :
-// new FreeSql.Generator.TemplateEngin.TemplateReturnInfo { Sb = tOuTpUt, Blocks = new Dictionary() };
-// Dictionary TPL__blocks = rTn.Blocks;
-// Stack TPL__blocks_stack = new Stack();
-// int[] TPL__blocks_stack_peek;
-// List TPL__forc = new List();
-// Func pRoCeSsOpTiOnS = new Func(delegate () {
-// IDictionary nEwoPtIoNs = new Hashtable();
-// foreach (DictionaryEntry oPtIoNs_dE in oPtIoNs)
-// nEwoPtIoNs[oPtIoNs_dE.Key] = oPtIoNs_dE.Value;
-// foreach (IDictionary TPL__forc_dIc in TPL__forc)
-// foreach (DictionaryEntry TPL__forc_dIc_dE in TPL__forc_dIc)
-// nEwoPtIoNs[TPL__forc_dIc_dE.Key] = TPL__forc_dIc_dE.Value;
-// return nEwoPtIoNs;
-// });
-// FreeSql.Generator.TemplateEngin.TemplateIf tPlIf = delegate (object exp) {
-// if (exp is bool) return (bool)exp;
-// if (exp == null) return false;
-// if (exp is int && (int)exp == 0) return false;
-// if (exp is string && (string)exp == string.Empty) return false;
-// if (exp is long && (long)exp == 0) return false;
-// if (exp is short && (short)exp == 0) return false;
-// if (exp is byte && (byte)exp == 0) return false;
-// if (exp is double && (double)exp == 0) return false;
-// if (exp is float && (float)exp == 0) return false;
-// if (exp is decimal && (decimal)exp == 0) return false;
-// return true;
-// };
-// FreeSql.Generator.TemplateEngin.TemplatePrint print = delegate (object[] pArMs) {
-// if (pArMs == null || pArMs.Length == 0) return;
-// foreach (object pArMs_A in pArMs) if (pArMs_A != null) tOuTpUt.Append(pArMs_A);
-// };
-// FreeSql.Generator.TemplateEngin.TemplatePrint Print = prin
-// dynamic index = oPtIoNs["index"];
-// dynamic col = oPtIoNs["col"];
-// dynamic table = oPtIoNs["table"];
-// dynamic dbfirst = oPtIoNs["dbfirst"]; t;
-// tOuTpUt.Append("using System;\r\nusing System.Collections;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Reflection;\r\nusing System.Threading.Tasks;\r\nusing Newtonsoft.Json;\r\nusing FreeSql.DataAnnotations;\r\n");
-
-// var dbf = dbfirst as FreeSql.IDbFirst;
-// var cols = (table.Columns as List);
-
-// Func UString = stra => stra.Substring(0, 1).ToUpper() + stra.Substring(1);
-// Func GetCsType = cola3 => {
-// if (cola3.DbType == (int)MySql.Data.MySqlClient.MySqlDbType.Enum || cola3.DbType == (int)MySql.Data.MySqlClient.MySqlDbType.Set) {
-// return $"{UString(cola3.Table.Name)}{cola3.Name.ToUpper()}{(cola3.IsNullable ? "?" : "")}";
-// }
-// return dbf.GetCsType(cola3);
-// };
-
-// tOuTpUt.Append("\r\nnamespace test.Model {\r\n\r\n [JsonObject(MemberSerialization.OptIn), Table(Name = \"");
-// Print(!string.IsNullOrEmpty(table.Schema) ? table.Schema + "." : "");
-// tOuTpUt.Append("");
-// Print(table.Name);
-// tOuTpUt.Append("\"");
-// if (tPlIf(cols.Where(cola003 => cola003.Name.ToLower() == "is_deleted" || cola003.Name.ToLower() == "isdeleted").Any())) {
-// tOuTpUt.Append(", SelectFilter = \"a.IsDeleted = 1\"");
-// }
-// tOuTpUt.Append(")]\r\n public partial class ");
-// Print(UString(table.Name));
-// tOuTpUt.Append(" {");
-// //new Action(delegate () {
-// IDictionary TPL__tmp1 = new Hashtable();
-// TPL__forc.Add(TPL__tmp1);
-// var TPL__tmp2 = table.Columns;
-// var TPL__tmp3 = col;
-// var TPL__tmp4 = index;
-// index = 0;
-// if (TPL__tmp2 != null)
-// foreach (var TPL__tmp5 in TPL__tmp2) {
-// TPL__tmp1["index"] = ++index;
-// TPL__tmp1["col"] = TPL__tmp5;
-// col = TPL__tmp5;
-// tOuTpUt.Append("\r\n ");
-// if (tPlIf(string.IsNullOrEmpty(col.Coment) == false)) {
-// tOuTpUt.Append("/// \r\n /// ");
-// Print(col.Coment.Replace("\r\n", "\n").Replace("\n", "\r\n /// "));
-// tOuTpUt.Append("\r\n /// ");
-// }
-// tOuTpUt.Append("\r\n [JsonProperty, Column(Name = \"");
-// Print(col.Name);
-// tOuTpUt.Append("\", DbType = \"");
-// Print(col.DbTypeTextFull);
-// tOuTpUt.Append("\"");
-// if (tPlIf(col.IsPrimary == true)) {
-// tOuTpUt.Append(", IsPrimary = true");
-// }
-// tOuTpUt.Append("");
-// if (tPlIf(col.IsIdentity == true)) {
-// tOuTpUt.Append(", IsIdentity = true");
-// }
-// tOuTpUt.Append("");
-// if (tPlIf(col.IsNullable == true)) {
-// tOuTpUt.Append(", IsNullable = true");
-// }
-// tOuTpUt.Append(")]\r\n public ");
-// Print(GetCsType(col));
-// tOuTpUt.Append(" ");
-// Print(UString(col.Name));
-// tOuTpUt.Append(" { get; set; }\r\n ");
-// }
-// col = TPL__tmp3;
-// index = TPL__tmp4;
-// TPL__forc.RemoveAt(TPL__forc.Count - 1);
-// //})();
-// tOuTpUt.Append("\r\n }\r\n");
-// tEmPlAtEsEnDeR.RenderFile2(tOuTpUt, pRoCeSsOpTiOnS(), "../../include/enumtype.tpl", rEfErErFiLeNaMe);
-// tOuTpUt.Append("\r\n}");
-// return rTn;
-// }
-//}
-////}
+
\ No newline at end of file
diff --git a/FreeSql.Tests/Generator/SqlServerTemplateGeneratorTest.cs b/FreeSql.Tests/Generator/SqlServerTemplateGeneratorTest.cs
new file mode 100644
index 00000000..759fbb1f
--- /dev/null
+++ b/FreeSql.Tests/Generator/SqlServerTemplateGeneratorTest.cs
@@ -0,0 +1,27 @@
+using FreeSql.DataAnnotations;
+using FreeSql.Generator;
+using System;
+using Xunit;
+
+namespace FreeSql.Tests.Generator {
+ public class SqlServerTemplateGeneratorTest {
+
+ [Fact]
+ public void BuildSimpleEntity() {
+ var gen = new TemplateGenerator();
+ gen.Build(g.sqlserver.DbFirst, @"C:\Users\28810\Desktop\github\FreeSql\Templates\SqlServer\simple-entity", @"C:\Users\28810\Desktop\新建文件夹 (9)", "shop");
+ }
+
+ [Fact]
+ public void BuildSimpleEntityNavigationObject () {
+ var gen = new TemplateGenerator();
+ gen.Build(g.sqlserver.DbFirst, @"C:\Users\28810\Desktop\github\FreeSql\Templates\SqlServer\simple-entity-navigation-object", @"C:\Users\28810\Desktop\新建文件夹 (9)", "shop");
+ }
+
+ [Fact]
+ public void BuildRichEntityNavigationObject() {
+ var gen = new TemplateGenerator();
+ gen.Build(g.sqlserver.DbFirst, @"C:\Users\28810\Desktop\github\FreeSql\Templates\SqlServer\rich-entity-navigation-object", @"C:\Users\28810\Desktop\新建文件夹 (9)", "shop");
+ }
+ }
+}
diff --git a/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs b/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs
index 5e2f3e84..bbc0e659 100644
--- a/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs
+++ b/FreeSql.Tests/MySql/Curd/MySqlSelectTest.cs
@@ -343,9 +343,9 @@ namespace FreeSql.Tests.MySql {
query2.ToList();
//������϶����㲻��
- query = select.Where("a.clicks > 100 && a.id = ?id", new { id = 10 });
+ query = select.Where("a.clicks > 100 and a.id = ?id", new { id = 10 });
sql = query.ToSql().Replace("\r\n", "");
- Assert.Equal("SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.clicks > 100 && a.id = ?id)", sql);
+ Assert.Equal("SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.clicks > 100 and a.id = ?id)", sql);
query.ToList();
}
[Fact]
@@ -390,9 +390,9 @@ namespace FreeSql.Tests.MySql {
query2.ToList();
//������϶����㲻��
- query = select.WhereIf(true, "a.clicks > 100 && a.id = ?id", new { id = 10 });
+ query = select.WhereIf(true, "a.clicks > 100 and a.id = ?id", new { id = 10 });
sql = query.ToSql().Replace("\r\n", "");
- Assert.Equal("SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.clicks > 100 && a.id = ?id)", sql);
+ Assert.Equal("SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a WHERE (a.clicks > 100 and a.id = ?id)", sql);
query.ToList();
// ==========================================WhereIf(false)
@@ -437,7 +437,7 @@ namespace FreeSql.Tests.MySql {
query2.ToList();
//������϶����㲻��
- query = select.WhereIf(false, "a.clicks > 100 && a.id = ?id", new { id = 10 });
+ query = select.WhereIf(false, "a.clicks > 100 and a.id = ?id", new { id = 10 });
sql = query.ToSql().Replace("\r\n", "");
Assert.Equal("SELECT a.`Id` as1, a.`Clicks` as2, a.`TestTypeInfoGuid` as3, a.`Title` as4, a.`CreateTime` as5 FROM `tb_topic` a", sql);
query.ToList();
diff --git a/FreeSql.Tests/MySql/Expression/DateTimeTest.cs b/FreeSql.Tests/MySql/Expression/DateTimeTest.cs
new file mode 100644
index 00000000..c43aab04
--- /dev/null
+++ b/FreeSql.Tests/MySql/Expression/DateTimeTest.cs
@@ -0,0 +1,115 @@
+using FreeSql.DataAnnotations;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using Xunit;
+
+namespace FreeSql.Tests.MySql.Expression {
+ public class DateTimeTest {
+
+ ISelect select => g.mysql.Select();
+
+ [Table(Name = "tb_topic111333")]
+ class Topic {
+ [Column(IsIdentity = true, IsPrimary = true)]
+ public int Id { get; set; }
+ public int Clicks { get; set; }
+ public int TestTypeInfoGuid { get; set; }
+ public TestTypeInfo Type { get; set; }
+ public string Title { get; set; }
+ public DateTime CreateTime { get; set; }
+ }
+ [Table(Name = "TestTypeInfo333")]
+ class TestTypeInfo {
+ public int Guid { get; set; }
+ public int ParentId { get; set; }
+ public TestTypeParentInfo Parent { get; set; }
+ public string Name { get; set; }
+ public DateTime Time { get; set; }
+ }
+ [Table(Name = "TestTypeParentInfo23123")]
+ class TestTypeParentInfo {
+ public int Id { get; set; }
+ public string Name { get; set; }
+
+ public List Types { get; set; }
+ public DateTime Time2 { get; set; }
+ }
+
+ [Fact]
+ public void DayOfWeek() {
+ var data = new List