protected override object GetMetaValue(string key) { if (!columns.ContainsKey(key.ToLower())) { columns.Add(key.ToLower(), LinqDLRColumn.New <TLinqDLRColumn>($"{(BelongToTable==""?"":BelongToTable+".")}{key}", this)); } return(columns[key.ToLower()]); }
public CustomTable Select(Func <dynamic, object> q) { var c = q.Invoke(this); if (c is CustomTable) { SelectString = $"{AliasName}.*"; } else if (c is LinqDLRColumn) { SelectString = $"{AliasName}.{((LinqDLRColumn)c).Name}"; } else if (c is string) { SelectString = ComFunc.nvl(c); } else { var fields = c.GetType().GetTypeInfo().GetFields(BindingFlags.CreateInstance | BindingFlags.Public); if (fields.Length <= 0) { SelectString = $"{AliasName}.*"; } else { foreach (var f in fields) { if (f.FieldType == typeof(LinqDLRColumn)) { LinqDLRColumn s = (LinqDLRColumn)f.GetValue(c); SelectString += $",{s.ToString()} AS {f.Name}"; } else { SelectString += $",{f.Name}"; } } SelectString = SelectString.Substring(1); } } SQL = $"SELECT {SelectString} FROM {TableName}"; if (AliasName != TableName) { SQL += $" {AliasName}"; } if (!string.IsNullOrEmpty(Conditions)) { SQL += $" WHERE {Conditions}"; } if (!string.IsNullOrEmpty(OrderByString)) { SQL += $" ORDER BY {OrderByString}"; } return(this); }