public async Task <long> Insert(long currentUserId, T entity) { var resultParameters = new List <TParameter>(); SQLExecutor.AddParameter(resultParameters, SQLConstants.UPDATED_BY_PARAMETER_NAME, currentUserId, DbType.Int64); SQLExecutor.AddParameter(resultParameters, SQLConstants.UID_PARAMETER_NAME, entity.Uid, DbType.Guid); SQLExecutor.AddParameter(resultParameters, SQLConstants.NAME_PARAMETER_NAME, entity.Name, DbType.String); for (var i = 0; i < Fields.Length; i++) { var field = Fields[i]; if (BaseFields.Any(x => x.Name == field.Name)) { continue; } var parameter = GetParameterInfoFromField(entity, field); resultParameters.AddRange(parameter); } var id = await SQLExecutor.ExecuteSqlReturningValue <long>(QueryInsert, resultParameters); entity.Id = id; return(id); }
public override string ToString() { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb .Append(BaseFields.Name).AppendLine(" Base Fields: ") .AppendLine(BaseFields.ToString()) .AppendLine("Lists: ") .AppendLine(Lists == null ? "" : Lists.ToString()) .Append(Extensions.Name).AppendLine(" Extension Fields: ") .AppendLine(Extensions.ToString()) ; return(sb.ToString()); }
public void LoadTables() { if (ProviderName.IsNullOrWhiteSpace() || ConnectionString.IsNullOrWhiteSpace()) { throw new Exception($"数据库{Name}配置ProviderName/ConnectionString错误"); } var service = GetDatabaseService(ConnectionString); var filterTables = FilterTables.IsNullOrEmpty() ? new List <string>() : FilterTables.Split(new char[] { ',', ',' }).ToList(); var baseFields = BaseFields.IsNullOrEmpty() ? new List <string>() : BaseFields.Split(new char[] { ',', ',' }).ToList(); var tables = service.GetTableModels(filterTables, baseFields); Tables.AddRange(tables); }
/// <summary> /// 把传递过来的对象属性复制给另一个上下文中对象属性 /// </summary> /// <param name="source"></param> /// <param name="target"></param> public void AttachFieldsForEdit(TEntity source, TEntity target) { string[] ignoreFields = BaseFields.GetFields(); PropertyInfo[] pis = typeof(TEntity).GetProperties(); foreach (var pi in pis) { if (!ignoreFields.Contains(pi.Name)) { pi.SetValue(target, pi.GetValue(source)); } if (pi.Name == "UpdateTime") { pi.SetValue(target, DateTime.Now); } } }
/// <summary> /// 継承元のメンバーを追加する /// </summary> /// <param name="target">インスタンス</param> private void SetBaseMembers(INamedTypeSymbol target) { // ソースファイル以外はそのまま終了 if (!string.IsNullOrEmpty(target.ContainingAssembly.MetadataName)) { return; } var targetName = target.Name; // スーパークラスからメンバを追加 if (target.BaseType != null) { SetBaseMembers(target.BaseType); } // メンバを追加 foreach (var memberName in target.MemberNames) { var targetMembers = target.GetMembers(memberName); if (!targetMembers.Any()) { continue; } foreach (var targetMember in targetMembers) { // privateスコープは継承対象外 if (targetMember.DeclaredAccessibility == Accessibility.Private) { continue; } var memberValue = targetMember.ToDisplayString(SymbolDisplayFormat.MinimallyQualifiedFormat); memberValue = memberValue.Replace($"{targetName}.", string.Empty, StringComparison.CurrentCulture); memberValue = $"{targetMember.DeclaredAccessibility} ".ToLower(CultureInfo.CurrentCulture) + memberValue; switch (targetMember.Kind) { case SymbolKind.Field: BaseFields.Add($"{memberValue};"); break; case SymbolKind.Property: var prop = targetMember as IPropertySymbol; var accessorList = new List <string>(); if (prop.SetMethod != null) { accessorList.Add("set;"); } if (prop.GetMethod != null) { accessorList.Add("get;"); } if (memberValue.Any()) { memberValue += "{"; foreach (var accessor in accessorList) { memberValue += accessor; } memberValue += "}"; } BaseProperties.Add(memberValue); break; case SymbolKind.Method: BaseMethods.Add(memberValue); break; } } } }