mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-20 04:48:16 +08:00
- 增加 ToDataTableByPropertyName 动态查询功能;
This commit is contained in:
@ -19,6 +19,25 @@ namespace FreeSql.Internal.CommonProvider
|
||||
{
|
||||
partial class Select0Provider<TSelect, T1>
|
||||
{
|
||||
public DataTable ToDataTableByPropertyName(string[] properties)
|
||||
{
|
||||
if (properties?.Any() != true) throw new ArgumentException($"properties 参数不能为空");
|
||||
var sbfield = new StringBuilder();
|
||||
for (var propIdx = 0; propIdx < properties.Length; propIdx++)
|
||||
{
|
||||
var property = properties[propIdx];
|
||||
var exp = ConvertStringPropertyToExpression(property);
|
||||
if (exp == null) throw new Exception($"{property} 属性名无法找到");
|
||||
var field = _commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, exp, true, null);
|
||||
if (propIdx > 0) sbfield.Append(", ");
|
||||
sbfield.Append(field);
|
||||
//if (field != property)
|
||||
sbfield.Append(_commonUtils.FieldAsAlias(_commonUtils.QuoteSqlName("test").Replace("test", property)));
|
||||
}
|
||||
var sbfieldStr = sbfield.ToString();
|
||||
sbfield.Clear();
|
||||
return ToDataTable(sbfieldStr);
|
||||
}
|
||||
public DataTable ToDataTable(string field = null)
|
||||
{
|
||||
DataTable ret = null;
|
||||
|
Reference in New Issue
Block a user