- 优化 FluentApi 继承关系可直接 ConfigEntity<BaseEntity> 生效;#1144

This commit is contained in:
2881099
2022-06-03 16:09:20 +08:00
parent 8263379720
commit f842e213eb
7 changed files with 257 additions and 186 deletions

View File

@ -849,7 +849,7 @@ FROM [tb_topic22] a", subquery);
});
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, isnull((SELECT min(b.[Id])
FROM [tb_topic22] b), 0) as6, isnull((SELECT min(b.[CreateTime])
FROM [tb_topic22] b), '1970-01-01 00:00:00.000') as7
FROM [tb_topic22] b), '1970-01-01 00:00:00') as7
FROM [tb_topic22] a", subquery);
var subqueryList = select.ToList(a => new
{
@ -869,7 +869,7 @@ FROM [tb_topic22] a", subquery);
});
Assert.Equal(@"SELECT a.[Id] as1, a.[Clicks] as2, a.[TypeGuid] as3, a.[Title] as4, a.[CreateTime] as5, isnull((SELECT max(b.[Id])
FROM [tb_topic22] b), 0) as6, isnull((SELECT max(b.[CreateTime])
FROM [tb_topic22] b), '1970-01-01 00:00:00.000') as7
FROM [tb_topic22] b), '1970-01-01 00:00:00') as7
FROM [tb_topic22] a", subquery);
var subqueryList = select.ToList(a => new
{

View File

@ -1,4 +1,6 @@
using FreeSql.DataAnnotations;
using FreeSql.DataAnnotations;
using FreeSql.Internal;
using FreeSql.Internal.Model;
using MySql.Data.MySqlClient;
using System;
using System.Linq;
@ -54,6 +56,37 @@ namespace FreeSql.Tests.DataAnnotations
};
var tsql1 = g.mysql.Select<ModelAopConfigEntity>().WhereDynamic(1).ToSql();
using (var fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, "Data Source=:memory:")
.UseAutoSyncStructure(true)
.UseMappingPriority(MappingPriorityType.Attribute, MappingPriorityType.Aop, MappingPriorityType.FluentApi)
.Build())
{
ColumnInfo localFunc1() => fsql.CodeFirst.GetTableByEntity(typeof(ModelAopConfigEntity01)).Columns["CreatedTime"];
ColumnInfo localFunc2() => fsql.CodeFirst.GetTableByEntity(typeof(ModelAopConfigEntity02)).Columns["CreatedTime"];
Assert.Equal(DateTimeKind.Local, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Local, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntityBase>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Utc));
Assert.Equal(DateTimeKind.Utc, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Utc, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntityBase>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Local));
Assert.Equal(DateTimeKind.Local, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Local, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntity01>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Utc));
Assert.Equal(DateTimeKind.Utc, localFunc1().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntity02>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Utc));
Assert.Equal(DateTimeKind.Utc, localFunc2().Attribute.ServerTime);
fsql.CodeFirst.ConfigEntity<ModelAopConfigEntityBase>(a => a.Property(b => b.CreatedTime).ServerTime(DateTimeKind.Local));
Assert.Equal(DateTimeKind.Utc, localFunc1().Attribute.ServerTime);
Assert.Equal(DateTimeKind.Utc, localFunc2().Attribute.ServerTime);
}
}
[System.ComponentModel.DataAnnotations.Schema.Table("xxx")]
class ModelAopConfigEntity
@ -62,6 +95,17 @@ namespace FreeSql.Tests.DataAnnotations
[Column(IsPrimary = false)]
public int pkid { get; set; }
}
class ModelAopConfigEntityBase
{
[Column(CanUpdate = false, ServerTime = DateTimeKind.Local)]
public virtual DateTime CreatedTime { get; set; }
}
class ModelAopConfigEntity01 : ModelAopConfigEntityBase
{
}
class ModelAopConfigEntity02 : ModelAopConfigEntityBase
{
}
[Fact]
public void Fluent()

View File

@ -1,4 +1,4 @@
using FreeSql.DataAnnotations;
using FreeSql.DataAnnotations;
using FreeSql.Tests.DataContext.SqlServer;
using System;
using System.Data.SqlClient;
@ -50,7 +50,7 @@ namespace FreeSql.Tests.DataAnnotations
{
a.Name("xxdkdkdk1222");
a.Property("Id").Name("Id22dd").IsIdentity(true);
a.Property("Name").DbType("varchar(101)").IsNullable(true);
a.Property("Name").Name("Name").DbType("varchar(101)").IsNullable(true);
})
.ConfigEntity<TestFluenttb2>(a =>