mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-02 03:13:58 +08:00
-
This commit is contained in:
@@ -64,6 +64,7 @@
|
|||||||
<Compile Include="UnitTest\ExpressionTest\ExpTestBase.cs" />
|
<Compile Include="UnitTest\ExpressionTest\ExpTestBase.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Field.cs" />
|
||||||
<Compile Include="UnitTest\Insert.cs" />
|
<Compile Include="UnitTest\Insert.cs" />
|
||||||
|
<Compile Include="UnitTest\Mapping .cs" />
|
||||||
<Compile Include="UnitTest\Query\JoinQuery.cs" />
|
<Compile Include="UnitTest\Query\JoinQuery.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Method.cs" />
|
||||||
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
<Compile Include="UnitTest\ExpressionTest\Select.cs" />
|
||||||
|
|||||||
31
OrmTest/UnitTest/Mapping .cs
Normal file
31
OrmTest/UnitTest/Mapping .cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using OrmTest.Models;
|
||||||
|
using SqlSugar;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace OrmTest.UnitTest
|
||||||
|
{
|
||||||
|
public class Mapping:ExpTestBase
|
||||||
|
{
|
||||||
|
private Mapping() { }
|
||||||
|
public Mapping(int eachCount)
|
||||||
|
{
|
||||||
|
this.Count = eachCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Init() {
|
||||||
|
|
||||||
|
var db = GetInstance();
|
||||||
|
var s1= db.Queryable<Student>().ToSql();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SqlSugarClient GetInstance()
|
||||||
|
{
|
||||||
|
SqlSugarClient db = new SqlSugarClient(new AttrbuitesCofnig() { ConnectionString = Config.ConnectionString, DbType = DbType.SqlServer, IsAutoCloseConnection = true, EntityNamespace= "OrmTest.Models" });
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,33 +86,36 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
this.GetTableInfoList();
|
this.GetTableInfoList();
|
||||||
}
|
}
|
||||||
var entity = this.Context.MappingTables.SingleOrDefault(it => it.DbTableName.Equals(tableName, StringComparison.CurrentCultureIgnoreCase));
|
var entities = this.Context.MappingTables.Where(it => it.DbTableName.Equals(tableName, StringComparison.CurrentCultureIgnoreCase)).ToList();
|
||||||
var entityName = entity == null ? tableName : entity.EntityName;
|
foreach (var entity in entities)
|
||||||
var assembly = Assembly.Load(this.Context.EntityNamespace.Split('.').First());
|
|
||||||
foreach (var item in assembly.GetType(this.Context.EntityNamespace + "." + entityName).GetProperties())
|
|
||||||
{
|
{
|
||||||
var isVirtual = item.GetGetMethod().IsVirtual;
|
var entityName = entity == null ? tableName : entity.EntityName;
|
||||||
if (isVirtual) continue;
|
var assembly = Assembly.Load(this.Context.EntityNamespace.Split('.').First());
|
||||||
var sugarColumn = item.GetCustomAttributes(typeof(SugarColumn), true)
|
foreach (var item in assembly.GetType(this.Context.EntityNamespace + "." + entityName).GetProperties())
|
||||||
.Where(it => it is SugarColumn)
|
|
||||||
.Select(it => (SugarColumn)it)
|
|
||||||
.Where(it => it.ColumnName.IsValuable())
|
|
||||||
.FirstOrDefault();
|
|
||||||
if (sugarColumn.IsNullOrEmpty())
|
|
||||||
{
|
{
|
||||||
reval.Add(new DbColumnInfo() { ColumnName = item.Name });
|
var isVirtual = item.GetGetMethod().IsVirtual;
|
||||||
}
|
if (isVirtual) continue;
|
||||||
else
|
var sugarColumn = item.GetCustomAttributes(typeof(SugarColumn), true)
|
||||||
{
|
.Where(it => it is SugarColumn)
|
||||||
if (sugarColumn.IsIgnore == false)
|
.Select(it => (SugarColumn)it)
|
||||||
|
.Where(it => it.ColumnName.IsValuable())
|
||||||
|
.FirstOrDefault();
|
||||||
|
if (sugarColumn.IsNullOrEmpty())
|
||||||
{
|
{
|
||||||
var columnInfo = new DbColumnInfo();
|
reval.Add(new DbColumnInfo() { ColumnName = item.Name });
|
||||||
columnInfo.ColumnName = sugarColumn.ColumnName.IsNullOrEmpty() ? item.Name : sugarColumn.ColumnName;
|
}
|
||||||
columnInfo.IsPrimarykey = sugarColumn.IsPrimaryKey;
|
else
|
||||||
columnInfo.IsIdentity = sugarColumn.IsIdentity;
|
{
|
||||||
columnInfo.ColumnDescription = sugarColumn.ColumnDescription;
|
if (sugarColumn.IsIgnore == false)
|
||||||
columnInfo.TableName = entity.IsNullOrEmpty() ? tableName : entity.DbTableName;
|
{
|
||||||
reval.Add(columnInfo);
|
var columnInfo = new DbColumnInfo();
|
||||||
|
columnInfo.ColumnName = sugarColumn.ColumnName.IsNullOrEmpty() ? item.Name : sugarColumn.ColumnName;
|
||||||
|
columnInfo.IsPrimarykey = sugarColumn.IsPrimaryKey;
|
||||||
|
columnInfo.IsIdentity = sugarColumn.IsIdentity;
|
||||||
|
columnInfo.ColumnDescription = sugarColumn.ColumnDescription;
|
||||||
|
columnInfo.TableName = entity.IsNullOrEmpty() ? tableName : entity.DbTableName;
|
||||||
|
reval.Add(columnInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user