导航属性规则制约、ISelect 增加 AsSelect 用于集合属性进行子查询,自动联表查询,以及MySql实现与部分测试

This commit is contained in:
28810
2019-03-16 08:00:07 +08:00
parent 23d5d33bdd
commit 3974c35b2f
54 changed files with 3423 additions and 2239 deletions

View File

@ -13,7 +13,7 @@ namespace FreeSql.Tests {
public class Order {
[Column(IsPrimary = true)]
public int OrderID { get; set; }
public int Id { get; set; }
public string OrderTitle { get; set; }
public string CustomerName { get; set; }
public DateTime TransactionDate { get; set; }
@ -21,7 +21,7 @@ namespace FreeSql.Tests {
}
public class OrderDetail {
[Column(IsPrimary = true)]
public int DetailId { get; set; }
public int Id { get; set; }
public int OrderId { get; set; }
public virtual Order Order { get; set; }
@ -31,19 +31,44 @@ namespace FreeSql.Tests {
[Fact]
public void Test1() {
var parentSelect1 = select.Where(a => a.Type.Parent.Parent.Parent.Parent.Name == "").Where(b => b.Type.Name == "").ToSql();
var collSelect1 = g.mysql.Select<Order>().Where(a =>
a.OrderDetails.AsSelect().Where(b => b.OrderId == a.OrderID).Any()
a.OrderDetails.AsSelect().Any(b => b.Id > 100)
);
var collectionSelect = select.Where(a =>
a.Type.Guid == a.TypeGuid &&
a.Type.Parent.Id == a.Type.ParentId &&
a.Type.Parent.Types.AsSelect().Where(b => b.Name == a.Title).Any(b => b.ParentId == a.Type.Parent.Id)
//a.Type.Guid == a.TypeGuid &&
//a.Type.Parent.Id == a.Type.ParentId &&
a.Type.Parent.Types.AsSelect().Where(b => b.Name == a.Title).Any(
//b => b.ParentId == a.Type.Parent.Id
)
);
var collectionSelect2 = select.Where(a =>
a.Type.Parent.Types.AsSelect().Where(b => b.Name == a.Title).Any(
b => b.Parent.Name == "xxx" && b.Parent.Parent.Name == "ccc"
&& b.Parent.Parent.Parent.Types.AsSelect().Any(cb => cb.Name == "yyy")
)
);
var collectionSelect3 = select.Where(a =>
a.Type.Parent.Types.AsSelect().Where(b => b.Name == a.Title).Any(
bbb => bbb.Parent.Types.AsSelect().Where(lv2 => lv2.Name == bbb.Name + "111").Any(
)
)
);
var order = g.mysql.Select<Order>().Where(a => a.OrderID == 1).ToOne(); //<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var order = g.mysql.Select<Order>().Where(a => a.Id == 1).ToOne(); //<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (order == null) {
var orderId = g.mysql.Insert(new Order { }).ExecuteIdentity();
order = g.mysql.Select<Order>(orderId).ToOne();
}
var orderDetail1 = order.OrderDetails; //<2F><>һ<EFBFBD>η<EFBFBD><CEB7>ʣ<EFBFBD><CAA3><EFBFBD>ѯ<EFBFBD><D1AF><EFBFBD>ݿ<EFBFBD>
var orderDetail2 = order.OrderDetails; //<2F>ڶ<EFBFBD><DAB6>η<EFBFBD><CEB7>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD>
var order1 = orderDetail1.FirstOrDefault(); //<2F><><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><D4A3><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ⣬<DDBF><E2A3AC>Ϊ OrderDetails <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˸<EFBFBD><CBB8><EFBFBD><EFBFBD><EFBFBD>
@ -206,6 +231,7 @@ namespace FreeSql.Tests {
}
class TestTypeInfo {
[Column(IsIdentity = true)]
public int Guid { get; set; }
public int ParentId { get; set; }
public TestTypeParentInfo Parent { get; set; }
@ -216,6 +242,9 @@ namespace FreeSql.Tests {
public int Id { get; set; }
public string Name { get; set; }
public int ParentId { get; set; }
public TestTypeParentInfo Parent { get; set; }
public List<TestTypeInfo> Types { get; set; }
}
}