- 修复 ISelect.ToList(true) 无效的 bug;

- 增加 IAop.ConfigEntity 配置实体特性,可实现使用其他 ORM 的实体特性,#36;
This commit is contained in:
28810
2019-04-24 15:09:32 +08:00
parent b16218d779
commit e2d33e943f
10 changed files with 164 additions and 36 deletions

View File

@ -1,6 +1,6 @@
using FreeSql.DataAnnotations;
using FreeSql.Tests.DataContext.SqlServer;
using System;
using System.Linq;
using Xunit;
namespace FreeSql.Tests.DataAnnotations {
@ -9,6 +9,31 @@ namespace FreeSql.Tests.DataAnnotations {
public MySqlFluentTest() {
}
[Fact]
public void AopConfigEntity() {
g.mysql.CodeFirst.ConfigEntity<ModelAopConfigEntity>(a => a.Property(b => b.pkid).IsPrimary(true));
g.mysql.Aop.ConfigEntity = (s, e) => {
var attr = e.EntityType.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.Schema.TableAttribute), false).FirstOrDefault() as System.ComponentModel.DataAnnotations.Schema.TableAttribute;
if (attr != null) {
e.ModifyResult.Name = attr.Name;
}
};
g.mysql.Aop.ConfigEntityProperty = (s, e) => {
if (e.Property.GetCustomAttributes(typeof(System.ComponentModel.DataAnnotations.KeyAttribute), false).Any()) {
e.ModifyResult.IsPrimary = true;
}
};
var tsql1 = g.mysql.Select<ModelAopConfigEntity>().WhereDynamic(1).ToSql();
}
[System.ComponentModel.DataAnnotations.Schema.Table("xxx")]
class ModelAopConfigEntity {
[System.ComponentModel.DataAnnotations.Key]
[Column(IsPrimary = false)]
public int pkid { get; set; }
}
[Fact]
public void Fluent() {
g.mysql.CodeFirst

View File

@ -7,10 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="FreeSql.DbContext" Version="0.5.3" />
<PackageReference Include="FreeSql.DbContext" Version="0.5.4" />
</ItemGroup>
<ItemGroup>

View File

@ -677,7 +677,7 @@ namespace FreeSql.Tests.SqlServer {
[Fact]
public void AsTable() {
var listt = select.AsTable((a, b) => "(select * from tb_topic where clicks > 10)").Page(1, 10).ToList();
var listt = select.AsTable((a, b) => "(select * from tb_topic22 where clicks > 10)").Page(1, 10).ToList();
Func<Type, string, string> tableRule = (type, oldname) => {
if (type == typeof(Topic)) return oldname + "AsTable1";

View File

@ -153,8 +153,23 @@ namespace FreeSql.Tests {
);
var neworder = new Order {
CustomerName = "testCustomer",
OrderTitle = "xxx#cccksksk",
TransactionDate = DateTime.Now,
OrderDetails = new List<OrderDetail>(new[] {
new OrderDetail {
var order = g.mysql.Select<Order>().Where(a => a.Id == 1).ToOne(); //查询订单表
},
new OrderDetail {
}
})
};
g.mysql.GetRepository<Order>().Insert(neworder);
var order = g.mysql.Select<Order>().Where(a => a.Id == neworder.Id).ToOne(); //查询订单表
if (order == null) {
var orderId = g.mysql.Insert(new Order { }).ExecuteIdentity();
order = g.mysql.Select<Order>(orderId).ToOne();