mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
update wiki
This commit is contained in:
parent
4bf8d60361
commit
b83b86f528
@ -85,7 +85,9 @@ namespace FreeSql.Tests.MySql {
|
|||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Lazy() {
|
public void Lazy() {
|
||||||
var tags = g.mysql.Select<Tag>().Where(a => a.Parent.Name == "xxx").LeftJoin(a => a.Parent_id == a.Parent.Id).ToList();
|
var tags = g.mysql.Select<Tag>().Where(a => a.Parent.Name == "xxx")
|
||||||
|
.LeftJoin(a => a.Parent_id == a.Parent.Id)
|
||||||
|
.ToSql();
|
||||||
|
|
||||||
var songs = g.mysql.Select<Song>().Limit(10).ToList();
|
var songs = g.mysql.Select<Song>().Limit(10).ToList();
|
||||||
|
|
||||||
|
@ -11,6 +11,22 @@ using Npgsql.LegacyPostgis;
|
|||||||
namespace FreeSql.Tests {
|
namespace FreeSql.Tests {
|
||||||
public class UnitTest1 {
|
public class UnitTest1 {
|
||||||
|
|
||||||
|
public class Order {
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public int OrderID { get; set; }
|
||||||
|
public string OrderTitle { get; set; }
|
||||||
|
public string CustomerName { get; set; }
|
||||||
|
public DateTime TransactionDate { get; set; }
|
||||||
|
public virtual List<OrderDetail> OrderDetails { get; set; }
|
||||||
|
}
|
||||||
|
public class OrderDetail {
|
||||||
|
[Column(IsPrimary = true)]
|
||||||
|
public int DetailId { get; set; }
|
||||||
|
|
||||||
|
public int OrderId { get; set; }
|
||||||
|
public virtual Order Order { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
class NullAggreTestTable {
|
class NullAggreTestTable {
|
||||||
[Column(IsIdentity = true)]
|
[Column(IsIdentity = true)]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
@ -20,6 +36,14 @@ namespace FreeSql.Tests {
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void Test1() {
|
public void Test1() {
|
||||||
|
|
||||||
|
var order = g.mysql.Select<Order>().Where(a => a.OrderID == 1).ToOne(); //查询订单表
|
||||||
|
var orderDetail1 = order.OrderDetails; //第一次访问,查询数据库
|
||||||
|
var orderDetail2 = order.OrderDetails; //第二次访问,不查
|
||||||
|
var order1 = orderDetail1.FirstOrDefault(); //访问导航属性,此时不查数据库,因为 OrderDetails 查询出来的时候已填充了该属性
|
||||||
|
|
||||||
|
|
||||||
|
var queryable = g.mysql.Queryable<TestInfo>().Where(a => a.Id == 1).ToList();
|
||||||
|
|
||||||
var sql2222 = select.Where(a =>
|
var sql2222 = select.Where(a =>
|
||||||
select.Where(b => b.Id == a.Id && select.Where(c => c.Id == b.Id).Where(d => d.Id == a.Id).Where(e => e.Id == b.Id)
|
select.Where(b => b.Id == a.Id && select.Where(c => c.Id == b.Id).Where(d => d.Id == a.Id).Where(e => e.Id == b.Id)
|
||||||
|
|
||||||
|
@ -10,6 +10,8 @@ using System.Reflection;
|
|||||||
|
|
||||||
public static class FreeSqlGlobalExtensions {
|
public static class FreeSqlGlobalExtensions {
|
||||||
|
|
||||||
|
public static FreeSql.ISelect<T> Queryable<T>(this IFreeSql freesql) where T : class => freesql.Select<T>();
|
||||||
|
|
||||||
static Lazy<Dictionary<Type, bool>> dicIsNumberType = new Lazy<Dictionary<Type, bool>>(() => new Dictionary<Type, bool> {
|
static Lazy<Dictionary<Type, bool>> dicIsNumberType = new Lazy<Dictionary<Type, bool>>(() => new Dictionary<Type, bool> {
|
||||||
[typeof(sbyte)] = true,
|
[typeof(sbyte)] = true,
|
||||||
[typeof(short)] = true,
|
[typeof(short)] = true,
|
||||||
|
@ -283,8 +283,15 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
if (dicfield.ContainsKey(quoteName)) field.Append(" as").Append(index);
|
||||||
else dicfield.Add(quoteName, true);
|
else dicfield.Add(quoteName, true);
|
||||||
} else {
|
} else {
|
||||||
var tb2 = _tables.Where((a, b) => b > 0 && a.Table.Type == prop.PropertyType && a.Alias.Contains(prop.Name)).FirstOrDefault(); //判断 b > 0 防止 parent 递归关系
|
var tb2 = _tables.Where((a, b) => b > 0 &&
|
||||||
if (tb2 == null && props.Where(pw => pw.Value.PropertyType == prop.PropertyType).Count() == 1) tb2 = _tables.Where((a, b) => b > 0 && a.Table.Type == prop.PropertyType).FirstOrDefault();
|
(a.Type == SelectTableInfoType.InnerJoin || a.Type == SelectTableInfoType.LeftJoin || a.Type == SelectTableInfoType.RightJoin) &&
|
||||||
|
string.IsNullOrEmpty(a.On) == false &&
|
||||||
|
a.Alias.Contains(prop.Name)).FirstOrDefault(); //判断 b > 0 防止 parent 递归关系
|
||||||
|
if (tb2 == null && props.Where(pw => pw.Value.PropertyType == prop.PropertyType).Count() == 1)
|
||||||
|
tb2 = _tables.Where((a, b) => b > 0 &&
|
||||||
|
(a.Type == SelectTableInfoType.InnerJoin || a.Type == SelectTableInfoType.LeftJoin || a.Type == SelectTableInfoType.RightJoin) &&
|
||||||
|
string.IsNullOrEmpty(a.On) == false &&
|
||||||
|
a.Table.Type == prop.PropertyType).FirstOrDefault();
|
||||||
if (tb2 == null) continue;
|
if (tb2 == null) continue;
|
||||||
foreach (var col2 in tb2.Table.Columns.Values) {
|
foreach (var col2 in tb2.Table.Columns.Values) {
|
||||||
if (index > 0) field.Append(", ");
|
if (index > 0) field.Append(", ");
|
||||||
|
33
readme.md
33
readme.md
@ -1,19 +1,24 @@
|
|||||||
# FreeSql
|
# FreeSql
|
||||||
|
|
||||||
FreeSql 是轻量化、可扩展和跨平台版的 .NETStandard 数据访问技术实现。
|
FreeSql是一个功能强大的NETStandard库,用于对象关系映射程序(O/RM),以便于开发人员能够使用 .NETStandard 对象来处理数据库,不必经常编写大部分数据访问代码。
|
||||||
|
|
||||||
FreeSql 可用作对象关系映射程序 (O/RM),以便于开发人员能够使用 .NETStandard 对象来处理数据库,不必经常编写大部分数据访问代码。
|
## 特性
|
||||||
|
|
||||||
FreeSql 支持 MySql/SqlServer/PostgreSQL/Oracle/Sqlite 数据库技术实现。
|
- [x] CodeFirst 迁移。
|
||||||
|
- [x] DbFirst 从数据库导入实体类,支持三种模板生成器。
|
||||||
|
- [x] 采用 ExpressionTree 高性能读取数据。
|
||||||
|
- [x] 类型映射深入支持,比如pgsql的数组类型,堪称匠心制作。
|
||||||
|
- [x] 支持丰富的表达式函数。
|
||||||
|
- [x] 支持导航属性查询,和延时加载。
|
||||||
|
- [x] 支持同步/异步数据库操作方法,丰富多彩的链式查询方法。
|
||||||
|
- [x] 支持事务。
|
||||||
|
- [x] 支持多种数据库,MySql/SqlServer/PostgreSQL/Oracle/Sqlite。
|
||||||
|
|
||||||
FreeSql 打造 .NETCore 最方便的 ORM,dbfirst codefirst混合使用,codefirst模式下的开发阶段,建好实体不用执行任何操作即能创建表和修改字段,dbfirst模式下提供api+模板自定义生成代码,作者提供了3种模板,您可以持续关注或者参与给出宝贵意见,QQ群:4336577。
|
[《Select查询数据文档》](https://github.com/2881099/FreeSql/wiki/%e6%9f%a5%e8%af%a2) | [《Update更新数据文档》](https://github.com/2881099/FreeSql/wiki/%e4%bf%ae%e6%94%b9) | [《Insert插入数据文档》](https://github.com/2881099/FreeSql/wiki/%e6%b7%bb%e5%8a%a0) | [《Delete删除数据文档》](https://github.com/2881099/FreeSql/wiki/%e5%88%a0%e9%99%a4)
|
||||||
|
|
||||||
|
[《Expression 表达式函数文档》](https://github.com/2881099/FreeSql/wiki/%e8%a1%a8%e8%be%be%e5%bc%8f%e5%87%bd%e6%95%b0) | [《CodeFirst 快速开发文档》](https://github.com/2881099/FreeSql/wiki/CodeFirst) | [《DbFirst 快速开发文档》](https://github.com/2881099/FreeSql/wiki/DbFirst)
|
||||||
|
|
||||||
[《Select查询数据文档》](Docs/select.md) | [《Update更新数据文档》](Docs/update.md) | [《Insert插入数据文档》](Docs/insert.md) | [《Delete删除数据文档》](Docs/delete.md)
|
## 快速开始
|
||||||
|
|
||||||
[《Expression 表达式函数文档》](Docs/expression.md) | [《CodeFirst 快速开发文档》](Docs/codefirst.md) | [《DbFirst 快速开发文档》](Docs/dbfirst.md)
|
|
||||||
|
|
||||||
# 快速开始
|
|
||||||
```csharp
|
```csharp
|
||||||
var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" +
|
var connstr = "Data Source=127.0.0.1;Port=3306;User ID=root;Password=root;" +
|
||||||
"Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10";
|
"Initial Catalog=cccddd;Charset=utf8;SslMode=none;Max pool size=10";
|
||||||
@ -158,7 +163,7 @@ List<xxx> t6 = fsql.Ado.Query<xxx>("select * from song");
|
|||||||
List<(int, string ,string)> t7 = fsql.Ado.Query<(int, string, string)>("select * from song");
|
List<(int, string ,string)> t7 = fsql.Ado.Query<(int, string, string)>("select * from song");
|
||||||
List<dynamic> t8 = fsql.Ado.Query<dynamic>("select * from song");
|
List<dynamic> t8 = fsql.Ado.Query<dynamic>("select * from song");
|
||||||
```
|
```
|
||||||
> 更多资料:[《Select查询数据》](Docs/select.md)
|
> 更多资料:[《Select查询数据》](https://github.com/2881099/FreeSql/wiki/%e6%9f%a5%e8%af%a2)
|
||||||
|
|
||||||
## 性能测试
|
## 性能测试
|
||||||
|
|
||||||
@ -221,7 +226,7 @@ var t6 = fsql.Insert<Topic>().AppendData(items)
|
|||||||
| ExecuteAffrows | long | 执行SQL语句,返回影响的行数 |
|
| ExecuteAffrows | long | 执行SQL语句,返回影响的行数 |
|
||||||
| ExecuteIdentity | long | 执行SQL语句,返回自增值 |
|
| ExecuteIdentity | long | 执行SQL语句,返回自增值 |
|
||||||
| ExecuteInserted | List\<Topic\> | 执行SQL语句,返回插入后的记录 |
|
| ExecuteInserted | List\<Topic\> | 执行SQL语句,返回插入后的记录 |
|
||||||
> 更多资料:[《Insert添加数据》](Docs/select.md)
|
> 更多资料:[《Insert添加数据》](https://github.com/2881099/FreeSql/wiki/%e6%b7%bb%e5%8a%a0)
|
||||||
|
|
||||||
# Part3 修改
|
# Part3 修改
|
||||||
```csharp
|
```csharp
|
||||||
@ -298,13 +303,13 @@ var t10 = fsql.Update<Topic>().SetRaw("Title = {0}", "新标题").Where("Id = {0
|
|||||||
| - | - | - | - |
|
| - | - | - | - |
|
||||||
| ExecuteAffrows | long | | 执行SQL语句,返回影响的行数 |
|
| ExecuteAffrows | long | | 执行SQL语句,返回影响的行数 |
|
||||||
| ExecuteUpdated | List\<T1\> | | 执行SQL语句,返回更新后的记录 |
|
| ExecuteUpdated | List\<T1\> | | 执行SQL语句,返回更新后的记录 |
|
||||||
> 更多资料:[《Update更新数据》](Docs/select.md)
|
> 更多资料:[《Update更新数据》](https://github.com/2881099/FreeSql/wiki/%e4%bf%ae%e6%94%b9)
|
||||||
|
|
||||||
# Part4 删除
|
# Part4 删除
|
||||||
详情查看:[《Delete 删除数据》](Docs/delete.md)
|
详情查看:[《Delete 删除数据》](https://github.com/2881099/FreeSql/wiki/%e5%88%a0%e9%99%a4)
|
||||||
|
|
||||||
# Part5 表达式函数
|
# Part5 表达式函数
|
||||||
详情查看:[《Expression 表达式函数》](Docs/expression.md)
|
详情查看:[《Expression 表达式函数》](https://github.com/2881099/FreeSql/wiki/%e8%a1%a8%e8%be%be%e5%bc%8f%e5%87%bd%e6%95%b0)
|
||||||
|
|
||||||
# Part6 事务
|
# Part6 事务
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user