/// <summary> /// Code writer /// </summary> /// <param name="model"></param> /// <param name="contextName"></param> /// <param name="connectionString"></param> /// <param name="contextNamespace"></param> /// <param name="modelNamespace"></param> /// <param name="useDataAnnotations"></param> /// <param name="suppressConnectionStringWarning"></param> /// <returns></returns> public override string WriteCode(IModel model, string contextName, string connectionString, string contextNamespace, string modelNamespace, bool useDataAnnotations, bool suppressConnectionStringWarning) { string code = base.WriteCode(model, contextName, connectionString, contextNamespace, modelNamespace, useDataAnnotations, suppressConnectionStringWarning); code = CustomHelpers.commentedClass(code, string.Format("Model for the database '{0}'.", model.GetDatabaseName()), ""); // Pluralizer issue code = code.Replace("MessageSeenBies", "MessagesSeenBy"); foreach (var e in model.GetEntityTypes()) { string decl = string.Format("public virtual DbSet<{0}>", e.Name); StringBuilder comment = new StringBuilder(); comment.Append("\r\n\t\t/// <summary>"); comment.Append("\r\n\t\t/// Table '" + e.GetTableName() + "'"); if (!string.IsNullOrWhiteSpace(e.GetComment())) { comment.Append(":\r\n\t\t/// " + e.GetComment()); } comment.Append("\r\n\t\t/// </summary>"); comment.Append("\r\n\t\t" + decl); code = code.Replace(decl, comment.ToString()); } return(CustomHelpers.copyrightNotice + code); }
/// <summary> /// Code writer /// </summary> /// <param name="type"></param> /// <param name="namespace"></param> /// <param name="useDataAnnotations"></param> /// <returns></returns> public override string WriteCode(IEntityType type, string @namespace, bool useDataAnnotations) { string code = base.WriteCode(type, @namespace, useDataAnnotations); code = CustomHelpers.commentedClass(code, string.Format("Elements of the table '{0}'", type.GetTableName()), type.GetComment()); // Pluralizer issue code = code.Replace("MessageSeenBies", "MessagesSeenBy"); string constr = string.Format("public {0}()", type.Name); code = code.Replace(constr, "/// <summary>\r\n\t\t/// Entity constructor\r\n\t\t/// </summary>\r\n\t\t" + constr); foreach (var p in type.GetProperties()) { string decl = "public " + _code.Reference(p.ClrType) + " " + p.Name; StringBuilder comment = new StringBuilder(); comment.Append("\r\n\t\t/// <summary>"); comment.Append("\r\n\t\t/// Column '" + p.GetColumnName() + "'"); if (!string.IsNullOrWhiteSpace(p.GetComment())) { comment.Append(":\r\n\t\t/// " + p.GetComment()); } comment.Append("\r\n\t\t/// </summary>"); comment.Append("\r\n\t\t/// <remarks>Original field type: " + p.GetColumnType() + "</remarks>"); comment.Append("\r\n\t\t" + decl); code = code.Replace(decl, comment.ToString()); } var navi = type.GetNavigations().ToList(); if (navi.Any()) { foreach (var n in navi) { string ntype = n.IsCollection() ? $"ICollection<{n.GetTargetType().DisplayName()}>" : n.GetTargetType().DisplayName(); string decl = $"public virtual {ntype} {n.Name}"; StringBuilder comment = new StringBuilder(); comment.Append("\r\n\t\t/// <summary>"); comment.Append("\r\n\t\t/// " + n.ForeignKey); comment.Append("\r\n\t\t/// </summary>"); comment.Append("\r\n\t\t" + decl); code = code.Replace(decl, comment.ToString()); } } return(CustomHelpers.copyrightNotice + code); }