JsonInsertableProvider.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace SqlSugar
  7. {
  8. public partial class JsonInsertableProvider : IJsonInsertableProvider<JsonInsertResult>
  9. {
  10. public SqlObjectResult ToSql()
  11. {
  12. return this.ToSqlList().First();
  13. }
  14. public JsonInsertableProvider(ISqlSugarClient context, JObject jObject)
  15. {
  16. this.jObject = jObject;
  17. this.context = context;
  18. this.jsonCommonProvider = new JsonCommonProvider(context);
  19. }
  20. public JsonInsertResult ToResult()
  21. {
  22. var result=new JsonInsertResult();
  23. var sqlInfo = this.ToSqlList();
  24. var sqlInfoResult = sqlInfo.First();
  25. if (sqlInfoResult.JsonSqlType != JsonProviderType.InsertableIdentity)
  26. {
  27. result.InsertCount = this.context.Ado.ExecuteCommand(sqlInfoResult.Sql,sqlInfoResult.Parameters);
  28. }
  29. else
  30. {
  31. result.InsertCount = this.Count;
  32. result.IdentityValue = this.context.Ado.GetInt(sqlInfoResult.Sql, sqlInfoResult.Parameters);
  33. }
  34. return result;
  35. }
  36. public List<SqlObjectResult> ToSqlList()
  37. {
  38. return ToSqlHelper();
  39. }
  40. private void AppendAll(JsonQueryParameter jsonQueryParameter, JToken item)
  41. {
  42. var name = item.Path.ToLower();
  43. if (IsName(name))
  44. {
  45. AppendName(item);
  46. }
  47. else if (IsIdentity(name))
  48. {
  49. AppendIdentity(item);
  50. }
  51. else if (IsColumns(name))
  52. {
  53. AppendRow(item);
  54. }
  55. }
  56. public List<string> ToSqlString()
  57. {
  58. throw new NotImplementedException();
  59. }
  60. }
  61. }