Files
jinko.yikatong/Src/Dlhis.ScheduledTask/SqlGeneration.cs
2024-01-04 14:40:04 +08:00

35 lines
1.3 KiB
C#

using System.Linq;
using Dlhis.ScheduledTask.Entities;
namespace Dlhis
{
public class SqlGeneration
{
private static string _insertSql;
private static string _updateSql;
static SqlGeneration()
{
//""
var properties = typeof(GainfoSap).GetProperties();
var insertFields = properties
.Where(x => !x.IsDefined(typeof(IgnoreColumnAttribute), false))
.Where(x => !x.IsDefined(typeof(PkColumnAttribute), false))
.Select(x => x.Name);
_insertSql = $" insert into gainfo_sap({string.Join(",", insertFields)}) \r\n values \r\n ({string.Join(",", insertFields.Select(x => $"@{x}"))})";
var updateFields = properties
.Where(x => !x.IsDefined(typeof(IgnoreColumnAttribute), false))
.Where(x => !x.IsDefined(typeof(PkColumnAttribute), false))
.Where(x => !x.IsDefined(typeof(UpdateColumnAttribute), false))
.Select(x => x.Name);
_updateSql = $" update gainfo_sap set {string.Join(",", updateFields.Select(x => $"{x}=@{x}"))} \t\n where ename=@ename";
}
public static string InsertSql => _insertSql;
public static string UpdateSql => _updateSql;
}
}