Browse Source

-

pull/12/MERGE
sunkaixuan 8 years ago
parent
commit
8677e769c1
  1. 10
      OrmTest/UnitTest/Delete.cs
  2. 27
      OrmTest/UnitTest/Insert.cs
  3. 2
      SqlSugar/Abstract/Core/SqlBuilder/DMLBuilder/DeleteBuilder.cs
  4. 4
      SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs
  5. 6
      SqlSugar/SqlSugarAccessory.cs

10
OrmTest/UnitTest/Delete.cs

@ -22,14 +22,14 @@ namespace OrmTest
var db = GetInstance();
//by entity
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,
t1.Key,
null, "Delte t1 error"
);
//use lock
var t2 = db.Deleteable<Student>().With(SqlWith.RowLock).ToSql();
base.Check(@"DELETE FROM [Student] WITH(ROWLOCK) ",
base.Check(@"DELETE FROM [STudent] WITH(ROWLOCK) ",
null,
t2.Key,
null, "Delte t2 error"
@ -37,18 +37,18 @@ namespace OrmTest
//by primary key
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,
t3.Key,
null, "Delte tt error"
);
//by primary key array
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
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)
}, t5.Key, t5.Value, "Delte t5 error");
}

27
OrmTest/UnitTest/Insert.cs

@ -24,7 +24,7 @@ namespace OrmTest.UnitTest
//db.MappingColumns.Add("id","dbid", "Student");
var t1 = db.Insertable(insertObj).ToSql();
base.Check(@"INSERT INTO [Student]
base.Check(@"INSERT INTO [STudent]
([SchoolId],[Name],[CreateTime])
VALUES
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
@ -42,7 +42,7 @@ namespace OrmTest.UnitTest
db.IgnoreColumns = null;
//Only insert Name
var t3 = db.Insertable(insertObj).InsertColumns(it => new { it.Name }).ToSql();
base.Check(@"INSERT INTO [Student]
base.Check(@"INSERT INTO [STudent]
([Name])
VALUES
(@Name) ;SELECT SCOPE_IDENTITY();", new List<SugarParameter>() {
@ -52,7 +52,7 @@ namespace OrmTest.UnitTest
//Ignore Name and TestId
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])
VALUES
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
@ -64,7 +64,7 @@ namespace OrmTest.UnitTest
//Ignore Name and TestId
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])
VALUES
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
@ -75,29 +75,26 @@ new List<SugarParameter>() {
);
//Use Lock
var t6 = db.Insertable(insertObj).With(SqlWith.UpdLock).ToSql();
base.Check(@"INSERT INTO [Student] WITH(UPDLOCK)
([SchoolId],[Name],[CreateTime],[TestId])
base.Check(@"INSERT INTO [STudent] WITH(UPDLOCK)
([SchoolId],[Name],[CreateTime])
VALUES
(@SchoolId,@Name,@CreateTime,@TestId) ;SELECT SCOPE_IDENTITY();",
(@SchoolId,@Name,@CreateTime) ;SELECT SCOPE_IDENTITY();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId",0),
new SugarParameter("@CreateTime",Convert.ToDateTime("2010-1-1")),
new SugarParameter("@Name","jack"),
new SugarParameter("@TestId",0)
new SugarParameter("@Name","jack")
}, t6.Key, t6.Value, "Insert t6 error"
);
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();
base.Check(@"
INSERT INTO [Student]
([SchoolId],[CreateTime],[TestId])
base.Check(@"INSERT INTO [STudent]
([SchoolId],[CreateTime])
VALUES
(@SchoolId,@CreateTime,@TestId) ;SELECT SCOPE_IDENTITY();",
(@SchoolId,@CreateTime) ;SELECT SCOPE_IDENTITY();",
new List<SugarParameter>() {
new SugarParameter("@SchoolId", 0),
new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1")),
new SugarParameter("@TestId", 0)
new SugarParameter("@CreateTime", Convert.ToDateTime("2010-1-1"))
},
t8.Key,
t8.Value,

2
SqlSugar/Abstract/Core/SqlBuilder/DMLBuilder/DeleteBuilder.cs

@ -58,7 +58,7 @@ namespace SqlSugar
{
get
{
return "{0}=N'{1}'";
return "[{0}]=N'{1}'";
}
}

4
SqlSugar/Abstract/DeleteProvider/DeleteableProvider.cs

@ -63,7 +63,7 @@ namespace SqlSugar
primaryKeyValues.Add(value);
}
var inValueString = primaryKeyValues.ToArray().ToJoinSqlInVals();
Where(string.Format(DeleteBuilder.WhereInTemplate, primaryFields.Single(), inValueString));
Where(string.Format(DeleteBuilder.WhereInTemplate,SqlBuilder.GetTranslationColumnName(primaryFields.Single()), inValueString));
}
else
{
@ -140,7 +140,7 @@ namespace SqlSugar
string primaryField = null;
primaryField = GetPrimaryKeys().FirstOrDefault();
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;
}

6
SqlSugar/SqlSugarAccessory.cs

@ -64,6 +64,12 @@ namespace SqlSugar
}
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 (entityInfo.DbTableName != entityInfo.EntityName)

Loading…
Cancel
Save