mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 10:08:19 +08:00
-
This commit is contained in:
@@ -22,14 +22,14 @@ namespace OrmTest
|
|||||||
var db = GetInstance();
|
var db = GetInstance();
|
||||||
//by entity
|
//by entity
|
||||||
var t1= db.Deleteable<Student>().Where(new Student() { Id = 1 }).ToSql();
|
var t1= db.Deleteable<Student>().Where(new Student() { Id = 1 }).ToSql();
|
||||||
base.Check(@"DELETE FROM [Student] WHERE Id IN ('1') ",
|
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
|
||||||
null,
|
null,
|
||||||
t1.Key,
|
t1.Key,
|
||||||
null, "Delte t1 error"
|
null, "Delte t1 error"
|
||||||
);
|
);
|
||||||
//use lock
|
//use lock
|
||||||
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
|
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
|
||||||
base.Check(@"DELETE FROM [Student] WITH(ROWLOCK) ",
|
base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ",
|
||||||
null,
|
null,
|
||||||
t2.Key,
|
t2.Key,
|
||||||
null, "Delte t2 error"
|
null, "Delte t2 error"
|
||||||
@@ -37,18 +37,18 @@ namespace OrmTest
|
|||||||
|
|
||||||
//by primary key
|
//by primary key
|
||||||
var t3 = db.Deleteable<Student>().In(1).ToSql();
|
var t3 = db.Deleteable<Student>().In(1).ToSql();
|
||||||
base.Check(@"DELETE FROM [Student] WHERE Id IN ('1') ",
|
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1') ",
|
||||||
null,
|
null,
|
||||||
t3.Key,
|
t3.Key,
|
||||||
null, "Delte tt error"
|
null, "Delte tt error"
|
||||||
);
|
);
|
||||||
//by primary key array
|
//by primary key array
|
||||||
var t4 = db.Deleteable<Student>().In(new int[] { 1,2}).ToSql();
|
var t4 = db.Deleteable<Student>().In(new int[] { 1,2}).ToSql();
|
||||||
base.Check(@"DELETE FROM [Student] WHERE Id IN ('1','2') ", null, t4.Key, null, "Update t4 error");
|
base.Check(@"DELETE FROM [STudent] WHERE [Id] IN ('1','2') ", null, t4.Key, null, "Update t4 error");
|
||||||
|
|
||||||
//by expression
|
//by expression
|
||||||
var t5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql();
|
var t5 = db.Deleteable<Student>().Where(it=>it.Id==1).ToSql();
|
||||||
base.Check(@"DELETE FROM [Student] WHERE ( [Id] = @Id0 ) ", new List<SugarParameter>() {
|
base.Check(@"DELETE FROM [STudent] WHERE ( [ID] = @Id0 ) ", new List<SugarParameter>() {
|
||||||
new SugarParameter("@Id0",1)
|
new SugarParameter("@Id0",1)
|
||||||
}, t5.Key, t5.Value, "Delte t5 error");
|
}, t5.Key, t5.Value, "Delte t5 error");
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ namespace OrmTest.UnitTest
|
|||||||
//db.MappingColumns.Add("id","dbid", "Student");
|
//db.MappingColumns.Add("id","dbid", "Student");
|
||||||
|
|
||||||
var t1 = db.Insertable(insertObj).ToSql();
|
var t1 = db.Insertable(insertObj).ToSql();
|
||||||
base.Check(@"INSERT INTO [Student]
|
base.Check(@"INSERT INTO [STudent]
|
||||||
([SchoolId],[Name],[CreateTime])
|
([SchoolId],[Name],[CreateTime])
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
@@ -42,7 +42,7 @@ namespace OrmTest.UnitTest
|
|||||||
db.IgnoreColumns = null;
|
db.IgnoreColumns = null;
|
||||||
//Only insert Name
|
//Only insert Name
|
||||||
var t3 = db.Insertable(insertObj).InsertColumns(it => new { it.Name }).ToSql();
|
var t3 = db.Insertable(insertObj).InsertColumns(it => new { it.Name }).ToSql();
|
||||||
base.Check(@"INSERT INTO [Student]
|
base.Check(@"INSERT INTO [STudent]
|
||||||
([Name])
|
([Name])
|
||||||
VALUES
|
VALUES
|
||||||
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
|
||||||
@@ -52,7 +52,7 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
//Ignore Name and TestId
|
//Ignore Name and TestId
|
||||||
var t4 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
var t4 = db.Insertable(insertObj).IgnoreColumns(it => new { it.Name, it.TestId }).ToSql();
|
||||||
base.Check(@"INSERT INTO [Student]
|
base.Check(@"INSERT INTO [STudent]
|
||||||
([SchoolId],[CreateTime])
|
([SchoolId],[CreateTime])
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
@@ -64,7 +64,7 @@ namespace OrmTest.UnitTest
|
|||||||
|
|
||||||
//Ignore Name and TestId
|
//Ignore Name and TestId
|
||||||
var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
var t5 = db.Insertable(insertObj).IgnoreColumns(it => it == "Name" || it == "TestId").With(SqlWith.UpdLock).ToSql();
|
||||||
base.Check(@"INSERT INTO [Student] WITH(UPDLOCK)
|
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
|
||||||
([SchoolId],[CreateTime])
|
([SchoolId],[CreateTime])
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
@@ -75,29 +75,26 @@ new List<SugarParameter>() {
|
|||||||
);
|
);
|
||||||
//Use Lock
|
//Use Lock
|
||||||
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
|
||||||
base.Check(@"INSERT INTO [Student] WITH(UPDLOCK)
|
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
|
||||||
([SchoolId],[Name],[CreateTime],[TestId])
|
([SchoolId],[Name],[CreateTime])
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@Name,@CreateTime,@TestId) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId",0),
|
new SugarParameter("@SchoolId",0),
|
||||||
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
|
||||||
new SugarParameter("@Name","jack"),
|
new SugarParameter("@Name","jack")
|
||||||
new SugarParameter("@TestId",0)
|
|
||||||
}, t6.Key, t6.Value, "Insert t6 error"
|
}, t6.Key, t6.Value, "Insert t6 error"
|
||||||
);
|
);
|
||||||
|
|
||||||
var insertObj2 = new Student() { Name = null,SchoolId=0, CreateTime = Convert.ToDateTime("2010-1-1") };
|
var insertObj2 = new Student() { Name = null,SchoolId=0, CreateTime = Convert.ToDateTime("2010-1-1") };
|
||||||
var t8 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ToSql();
|
var t8 = db.Insertable(insertObj2).Where(true/* Is insert null */, true/*off identity*/).ToSql();
|
||||||
base.Check(@"
|
base.Check(@"INSERT INTO [STudent]
|
||||||
INSERT INTO [Student]
|
([SchoolId],[CreateTime])
|
||||||
([SchoolId],[CreateTime],[TestId])
|
|
||||||
VALUES
|
VALUES
|
||||||
(@SchoolId,@CreateTime,@TestId) ;SELECT SCOPE_IDENTITY();",
|
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
|
||||||
new List<SugarParameter>() {
|
new List<SugarParameter>() {
|
||||||
new SugarParameter("@SchoolId", 0),
|
new SugarParameter("@SchoolId", 0),
|
||||||
new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1")),
|
new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1"))
|
||||||
new SugarParameter("@TestId", 0)
|
|
||||||
},
|
},
|
||||||
t8.Key,
|
t8.Key,
|
||||||
t8.Value,
|
t8.Value,
|
||||||
|
@@ -58,7 +58,7 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return "{0}=N'{1}'";
|
return "[{0}]=N'{1}'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ namespace SqlSugar
|
|||||||
primaryKeyValues.Add(value);
|
primaryKeyValues.Add(value);
|
||||||
}
|
}
|
||||||
var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
|
var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
|
||||||
Where(string.Format(DeleteBuilder.WhereInTemplate, primaryFields.Single(), inValueString));
|
Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -140,7 +140,7 @@ namespace SqlSugar
|
|||||||
string primaryField = null;
|
string primaryField = null;
|
||||||
primaryField = GetPrimaryKeys().FirstOrDefault();
|
primaryField = GetPrimaryKeys().FirstOrDefault();
|
||||||
Check.ArgumentNullException(primaryField, "Table " + tableName + " with no primarykey");
|
Check.ArgumentNullException(primaryField, "Table " + tableName + " with no primarykey");
|
||||||
Where(string.Format(DeleteBuilder.WhereInTemplate, primaryField, primaryKeyValues.ToJoinSqlInVals()));
|
Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryField), primaryKeyValues.ToJoinSqlInVals()));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -64,6 +64,12 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
private void InitMppingInfo(EntityInfo entityInfo)
|
private void InitMppingInfo(EntityInfo entityInfo)
|
||||||
{
|
{
|
||||||
|
if (this.MappingTables == null)
|
||||||
|
this.MappingTables = new MappingTableList();
|
||||||
|
if (this.MappingColumns == null)
|
||||||
|
this.MappingColumns = new MappingColumnList();
|
||||||
|
if (this.IgnoreColumns == null)
|
||||||
|
this.IgnoreColumns = new IgnoreComumnList();
|
||||||
if (!this.MappingTables.Any(it => it.EntityName == entityInfo.EntityName))
|
if (!this.MappingTables.Any(it => it.EntityName == entityInfo.EntityName))
|
||||||
{
|
{
|
||||||
if (entityInfo.DbTableName != entityInfo.EntityName)
|
if (entityInfo.DbTableName != entityInfo.EntityName)
|
||||||
|
Reference in New Issue
Block a user