Browse Source

-

pull/12/MERGE
sunkaixuan 7 years ago
parent
commit
dcb26669ee
  1. 28
      Src/Asp.Net/OracleTest/Demos/1_Query.cs
  2. 2
      Src/Asp.Net/OracleTest/Models/Student.cs
  3. 4
      Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs
  4. 10
      Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs

28
Src/Asp.Net/OracleTest/Demos/1_Query.cs

@ -23,7 +23,7 @@ namespace OrmTest.Demo
Group();
Sqlable();
Tran();
StoredProcedure();
//StoredProcedure();
Enum();
Simple();
}
@ -50,28 +50,14 @@ namespace OrmTest.Demo
private static void StoredProcedure()
{
var db = GetInstance();
//1. no result
db.Ado.UseStoredProcedure(() =>
{
string spName = "sp_help";
var getSpReslut = db.Ado.SqlQueryDynamic(spName, new { objname = "student" });
});
//2. has result
var result = db.Ado.UseStoredProcedure<dynamic>(() =>
{
string spName = "sp_help";
return db.Ado.SqlQueryDynamic(spName, new { objname = "student" });
});
//2. has output
object outPutValue;
var outputResult = db.Ado.UseStoredProcedure<dynamic>(() =>
{
string spName = "sp_school";
var p1 = new SugarParameter("@p1", "1");
var p2 = new SugarParameter("@p2", null, true);//isOutput=true
var dbResult = db.Ado.SqlQueryDynamic(spName, new SugarParameter[] { p1, p2 });
string spName = "SpGetSchool";
var p1 = new SugarParameter("@id_in", "1");
var p2 = new SugarParameter("@name_out", null, true);//isOutput=true
var dbResult = db.Ado.ExecuteCommand(spName, new SugarParameter[] { p1, p2 });
outPutValue = p2.Value;
return dbResult;
});
@ -160,7 +146,7 @@ namespace OrmTest.Demo
var getNew = db.Queryable<Student>().Where(it => it.Id == 1).Select(it => new { id = SqlFunc.IIF(it.Id == 0, 1, it.Id), it.Name, it.SchoolId }).ToList();
var getAllNoLock = db.Queryable<Student>().With(SqlWith.NoLock).ToList();
var getByPrimaryKey = db.Queryable<Student>().InSingle(2);
var getSingleOrDefault = db.Queryable<Student>().Single();
var getSingleOrDefault = db.Queryable<Student>().Where(it=>it.Id==1).Single();
var getFirstOrDefault = db.Queryable<Student>().First();
var getByWhere = db.Queryable<Student>().Where(it => it.Id == 1 || it.Name == "a").ToList();
var getByFuns = db.Queryable<Student>().Where(it => SqlFunc.IsNullOrEmpty(it.Name)).ToList();

2
Src/Asp.Net/OracleTest/Models/Student.cs

@ -11,7 +11,7 @@ namespace OrmTest.Models
[SugarTable("STudent")]
public class Student
{
[SugarColumn(IsPrimaryKey = true, IsIdentity = true, ColumnName = "ID")]
[SugarColumn(IsPrimaryKey = true, ColumnName = "ID",OracleSequenceName = "seq_newsId")]
public int Id { get; set; }
public int? SchoolId { get; set; }
public string Name { get; set; }

4
Src/Asp.Net/SqlSugar/Realization/Oracle/OracleProvider.cs

@ -104,6 +104,10 @@ namespace SqlSugar
{
sqlParameter.ParameterName = ':' + sqlParameter.ParameterName.Substring(1, sqlParameter.ParameterName.Length - 1);
}
if (this.CommandType == CommandType.StoredProcedure)
{
sqlParameter.ParameterName = sqlParameter.ParameterName.TrimStart(':');
}
//sqlParameter.UdtTypeName = parameter.UdtTypeName;
sqlParameter.Size = parameter.Size;
sqlParameter.Value = parameter.Value;

10
Src/Asp.Net/SqlSugar/Realization/Oracle/SqlBuilder/OracleInsertBuilder.cs

@ -15,7 +15,7 @@ namespace SqlSugar
return @"INSERT INTO {0}
({1})
VALUES
({2}) ;";
({2}) ";
}
}
@ -28,13 +28,13 @@ namespace SqlSugar
}
var groupList = DbColumnInfoList.GroupBy(it => it.TableId).ToList();
var isSingle = groupList.Count() == 1;
string columnsString = string.Join(UtilConstants.Dot, groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
string columnsString = string.Join(",", groupList.First().Select(it => Builder.GetTranslationColumnName(it.DbColumnName)));
if (isSingle)
{
string columnParametersString = string.Join(UtilConstants.Dot, this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
string columnParametersString = string.Join(",", this.DbColumnInfoList.Select(it => Builder.SqlParameterKeyWord + it.DbColumnName));
if (identities.IsValuable()) {
columnsString = columnsString.TrimEnd(UtilConstants.DotChar) + UtilConstants.Dot + string.Join(UtilConstants.Dot, identities.Select(it=> Builder.GetTranslationColumnName(it.DbColumnName)));
columnParametersString = columnParametersString.TrimEnd(UtilConstants.DotChar) + UtilConstants.Dot + string.Join(UtilConstants.Dot, identities.Select(it =>it.OracleSequenceName));
columnsString = columnsString.TrimEnd(',') + "," + string.Join(",", identities.Select(it=> Builder.GetTranslationColumnName(it.DbColumnName)));
columnParametersString = columnParametersString.TrimEnd(',') +"," + string.Join(",", identities.Select(it =>it.OracleSequenceName+ ".nextval"));
}
return string.Format(SqlTemplate, GetTableNameString, columnsString, columnParametersString);
}

Loading…
Cancel
Save