Browse Source

-

pull/12/MERGE
sunkaixuan 6 years ago
parent
commit
360747a2b3
  1. 6
      Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs
  2. 37
      Src/Asp.Net/SqlServerTest/Demo/Demo5_SqlQueryable.cs
  3. 1
      Src/Asp.Net/SqlServerTest/Program.cs
  4. 1
      Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

6
Src/Asp.Net/SqlServerTest/Demo/Demo0_SqlSugarClient.cs

@ -40,9 +40,15 @@ namespace OrmTest
}
});
//if no exist create datebase SQLSUGAR4XTEST (bin/database/)
db.DbMaintenance.CreateDatabase();
//Use db
var dt = db.Ado.GetDataTable("select 1");
//create table OrderDetail
db.CodeFirst.InitTables(typeof(OrderItem));
db.Insertable(new OrderItem() { OrderId = 1, Price = 0 }).ExecuteCommand();
Console.WriteLine("#### SqlSugarClient End ####");

37
Src/Asp.Net/SqlServerTest/Demo/Demo5_SqlQueryable.cs

@ -0,0 +1,37 @@
using OrmTest.Models;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OrmTest
{
public class Demo5_SqlQueryable
{
public static void Init()
{
Console.WriteLine("");
Console.WriteLine("#### SqlQueryable Start ####");
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = Config.ConnectionString,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true
});
int total = 0;
var list = db.SqlQueryable<Student>("select * from student").ToPageList(1, 2, ref total);
//by expression
var list2 = db.SqlQueryable<Student>("select * from student").Where(it => it.Id == 1).ToPageList(1, 2);
//by sql
var list3 = db.SqlQueryable<Student>("select * from student").Where("id=@id", new { id = 1 }).ToPageList(1, 2);
Console.WriteLine("#### SqlQueryable End ####");
}
}
}

1
Src/Asp.Net/SqlServerTest/Program.cs

@ -17,6 +17,7 @@ namespace OrmTest
Democ_GobalFilter.Init();
DemoD_DbFirst.Init();
DemoE_CodeFirst.Init();
Demo5_SqlQueryable.Init();
//Unit test
NewUnitTest.Init();

1
Src/Asp.Net/SqlServerTest/SqlServerTest.csproj

@ -54,6 +54,7 @@
<Compile Include="Demo\Demo2_Updateable.cs" />
<Compile Include="Demo\Demo3_Insertable.cs" />
<Compile Include="Demo\Demo4_Deleteable.cs" />
<Compile Include="Demo\Demo5_SqlQueryable.cs" />
<Compile Include="Demo\DemoC_GobalFilter.cs" />
<Compile Include="Demo\Demo1_Queryable.cs" />
<Compile Include="Demo\DemoD_DbFirst.cs" />

Loading…
Cancel
Save