mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
-
This commit is contained in:
15
SqlServerTest/Demo/DbFirst.cs
Normal file
15
SqlServerTest/Demo/DbFirst.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class DbFirst
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class Delete
|
||||
public class Delete:DemoBase
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
@@ -29,17 +29,5 @@ namespace OrmTest.Demo
|
||||
//by expression
|
||||
var t5 = db.Deleteable<Student>().Where(it => it.Id == 1).ExecuteCommand();
|
||||
}
|
||||
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
23
SqlServerTest/Demo/DemoBase.cs
Normal file
23
SqlServerTest/Demo/DemoBase.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class DemoBase
|
||||
{
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
@@ -8,9 +8,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class Insert
|
||||
public class Insert:DemoBase
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
public static void Init() {
|
||||
var db = GetInstance();
|
||||
db.IgnoreColumns.Add("TestId", "Student");
|
||||
|
||||
@@ -50,17 +51,5 @@ namespace OrmTest.Demo
|
||||
}
|
||||
var s9 = db.Insertable(insertObjs.ToArray()).InsertColumns(it => new { it.Name }).ExecuteCommand();
|
||||
}
|
||||
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class Query
|
||||
public class Query:DemoBase
|
||||
{
|
||||
|
||||
public static void Init()
|
||||
@@ -273,18 +273,5 @@ namespace OrmTest.Demo
|
||||
.Select("st.*").ToList();
|
||||
//SELECT st.* FROM [Student] st Left JOIN School sh ON sh.id=st.schoolid WHERE st.id>@id
|
||||
}
|
||||
|
||||
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig{ ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,9 +8,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace OrmTest.Demo
|
||||
{
|
||||
public class Update
|
||||
public class Update : DemoBase
|
||||
{
|
||||
public static void Init()
|
||||
{
|
||||
public static void Init() {
|
||||
var db = GetInstance();
|
||||
var updateObj = new Student() { Id = 1, Name = "jack", SchoolId = 0, CreateTime = Convert.ToDateTime("2017-05-21 09:56:12.610") };
|
||||
var updateObjs = new List<Student>() { updateObj, new Student() { Id = 2, Name = "sun", SchoolId = 0 } }.ToArray();
|
||||
@@ -54,16 +55,5 @@ namespace OrmTest.Demo
|
||||
db.Updateable<School>().AS("Student").UpdateColumns(it => new School() { Name = "jack" }).Where(it => it.Id == 1).ExecuteCommand();
|
||||
//Update Student set Name='jack' Where Id=1
|
||||
}
|
||||
public static SqlSugarClient GetInstance()
|
||||
{
|
||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true });
|
||||
db.Ado.IsEnableLogEvent = true;
|
||||
db.Ado.LogEventStarting = (sql, pars) =>
|
||||
{
|
||||
Console.WriteLine(sql + "\r\n" + db.RewritableMethods.SerializeObject(pars));
|
||||
Console.WriteLine();
|
||||
};
|
||||
return db;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -48,7 +48,9 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Config.cs" />
|
||||
<Compile Include="Demo\DbFirst.cs" />
|
||||
<Compile Include="Demo\Delete.cs" />
|
||||
<Compile Include="Demo\DemoBase.cs" />
|
||||
<Compile Include="Demo\Insert.cs" />
|
||||
<Compile Include="Demo\Query.cs" />
|
||||
<Compile Include="Demo\Update.cs" />
|
||||
|
@@ -119,6 +119,13 @@ namespace SqlSugar
|
||||
public Dictionary<string, string> ToClassStringList(string nameSpace = "Models")
|
||||
{
|
||||
Dictionary<string, string> result = new Dictionary<string, string>();
|
||||
if (this.TableInfoList.IsValuable())
|
||||
{
|
||||
foreach (var tableInfo in this.TableInfoList)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
this.Namespace = nameSpace;
|
||||
return result;
|
||||
}
|
||||
@@ -132,9 +139,11 @@ namespace SqlSugar
|
||||
foreach (var item in classStringList)
|
||||
{
|
||||
string className = item.Key;
|
||||
if (this.Context.MappingTables.IsValuable()) {
|
||||
if (this.Context.MappingTables.IsValuable())
|
||||
{
|
||||
var mappingInfo = this.Context.MappingTables.FirstOrDefault(it => it.DbTableName.Equals(item.Key, StringComparison.CurrentCultureIgnoreCase));
|
||||
if (mappingInfo.IsValuable()) {
|
||||
if (mappingInfo.IsValuable())
|
||||
{
|
||||
className = mappingInfo.EntityName;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user