private static void ScaffoldRepositoryExtensionsClassDefinition(EntityFrameworkCoreProject project) => CSharpCodeBuilder.CreateFiles(project.OutputDirectory, project.GetDataLayerRepositoriesDirectory(), project.GlobalSelection().Settings.ForceOverwrite, project.GetRepositoryExtensionsClassDefinition());
public static string GetFullDbSetPropertyName(this EntityFrameworkCoreProject project, IDbObject dbObject) => project.NamingService.Pluralize(string.Concat(project.CodeNamingConvention.GetNamespace(dbObject.Schema), project.GetEntityName(dbObject)));
public static string GetFullEntityConfigurationName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Join(".", project.CodeNamingConvention.GetNamespace(project.ProjectNamespaces.Configurations), project.CodeNamingConvention.GetNamespace(dbObject.Schema), string.Format("{0}Configuration", project.GetEntityName(dbObject)));
public static string GetEntityResultName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Format("{0}Result", project.CodeNamingConvention.GetClassName(dbObject.Name));
public static string GetDbContextName(this EntityFrameworkCoreProject project, Database database) => project.CodeNamingConvention.GetClassName(string.Format("{0}DbContext", database.Name));
public static string GetParameterName(this EntityFrameworkCoreProject project, Column column) => project.CodeNamingConvention.GetParameterName(column.Name);
public static string GetNavigationPropertyName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Format("{0}List", project.CodeNamingConvention.GetClassName(dbObject.Name));
public static string GetGetRepositoryMethodName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Format("Get{0}Async", project.GetEntityName(dbObject));
public static string GetGetByUniqueRepositoryMethodName(this EntityFrameworkCoreProject project, ITable table, Unique unique) => string.Format("Get{0}By{1}Async", project.GetEntityName(table), string.Join("And", unique.Key.Select(item => project.CodeNamingConvention.GetPropertyName(item))));
public static string GetDataContractName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Format("{0}Dto", project.CodeNamingConvention.GetClassName(dbObject.Name));
public static string GetGetAllRepositoryMethodName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Format("Get{0}", project.GetPluralName(dbObject));
public static void AddDataAnnotations(this IDotNetClassDefinition classDefinition, IView view, EntityFrameworkCoreProject project) { classDefinition.Attributes.Add(new MetadataAttribute("Table", string.Format("\"{0}\"", view.Name)) { Sets = { new MetadataAttributeSet("Schema", string.Format("\"{0}\"", view.Schema)) } }); var primaryKeys = project .Database .Tables .Where(item => item.PrimaryKey != null) .Select(item => item.GetColumnsFromConstraint(item.PrimaryKey).Select(c => c.Name).First()) .ToList(); var result = view.Columns.Where(item => primaryKeys.Contains(item.Name)).ToList(); for (var i = 0; i < view.Columns.Count; i++) { var column = view.Columns[i]; foreach (var property in classDefinition.Properties) { if (column.GetPropertyName() != property.Name) { continue; } property.Attributes.Add(new MetadataAttribute("Column", string.Format("\"{0}\"", column.Name)) { Sets = { new MetadataAttributeSet("Order", (i + 1).ToString()) } }); if (!column.Nullable && primaryKeys.Contains(column.Name)) { property.Attributes.Add(new MetadataAttribute("Key")); } if (!column.Nullable) { property.Attributes.Add(new MetadataAttribute("Required")); } } } }
public static void AddDataAnnotations(this IDotNetClassDefinition classDefinition, ITable table, EntityFrameworkCoreProject project) { classDefinition.Attributes.Add(new MetadataAttribute("Table", string.Format("\"{0}\"", table.Name)) { Sets = { new MetadataAttributeSet("Schema", string.Format("\"{0}\"", table.Schema)) } }); var selection = project.GetSelection(table); for (var i = 0; i < table.Columns.Count; i++) { var column = table.Columns[i]; foreach (var property in classDefinition.Properties) { if (column.GetPropertyName() != property.Name) { continue; } if (table.Identity?.Name == column.Name) { property.Attributes.Add(new MetadataAttribute("DatabaseGenerated", "DatabaseGeneratedOption.Identity")); } if (table.PrimaryKey != null && table.PrimaryKey.Key.Contains(column.Name)) { property.Attributes.Add(new MetadataAttribute("Key")); } property.Attributes.Add(new MetadataAttribute("Column", string.Format("\"{0}\"", column.Name))); if (!column.Nullable && table.Identity != null && table.Identity.Name != column.Name) { property.Attributes.Add(new MetadataAttribute("Required")); } if (project.Database.ColumnIsString(column) && column.Length > 0) { property.Attributes.Add(new MetadataAttribute("StringLength", column.Length.ToString())); } if (!string.IsNullOrEmpty(selection.Settings.ConcurrencyToken) && selection.Settings.ConcurrencyToken == column.Name) { property.Attributes.Add(new MetadataAttribute("Timestamp")); } } } }
public static ProjectSelection <EntityFrameworkCoreProjectSettings> GetSelection(this EntityFrameworkCoreProject project, IDbObject dbObj) { // Sales.OrderHeader var selectionForFullName = project.Selections.FirstOrDefault(item => item.Pattern == dbObj.FullName); if (selectionForFullName != null) { return(selectionForFullName); } // Sales.* var selectionForSchema = project.Selections.FirstOrDefault(item => item.Pattern == string.Format("{0}.*", dbObj.Schema)); if (selectionForSchema != null) { return(selectionForSchema); } // *.OrderHeader var selectionForName = project.Selections.FirstOrDefault(item => item.Pattern == string.Format("*.{0}", dbObj.Name)); if (selectionForName != null) { return(selectionForName); } return(project.GlobalSelection()); }
public static string GetDataLayerDirectory(this EntityFrameworkCoreProject project, string subdirectory) => Path.Combine(project.OutputDirectory, project.ProjectNamespaces.DataLayer, subdirectory);
public static string GetRemoveRepositoryMethodName(this EntityFrameworkCoreProject project, ITable table) => string.Format("Remove{0}Async", project.GetEntityName(table));
public static string GetDataLayerConfigurationsDirectory(this EntityFrameworkCoreProject project, string schema) => Path.Combine(project.OutputDirectory, project.ProjectNamespaces.DataLayer, project.ProjectNamespaces.Configurations, schema);
public static string GetScalarFunctionMethodName(this EntityFrameworkCoreProject project, ScalarFunction scalarFunction) => string.Format("{0}{1}", project.CodeNamingConvention.GetClassName(scalarFunction.Schema), project.CodeNamingConvention.GetClassName(scalarFunction.Name));
public static string GetDataLayerRepositoriesDirectory(this EntityFrameworkCoreProject project) => Path.Combine(project.OutputDirectory, project.ProjectNamespaces.DataLayer, project.ProjectNamespaces.Repositories);
public static PropertyDefinition GetParentNavigationProperty(this ForeignKey foreignKey, ITable table, EntityFrameworkCoreProject project) { var propertyType = string.Join(".", (new string[] { project.Name, project.ProjectNamespaces.EntityLayer, project.Database.HasDefaultSchema(table) ? string.Empty : table.Schema, project.GetEntityName(table) }).Where(item => !string.IsNullOrEmpty(item))); var selection = project.GetSelection(table); return(new PropertyDefinition(propertyType, string.Format("{0}Fk", project.GetEntityName(table))) { IsVirtual = selection.Settings.DeclareNavigationPropertiesAsVirtual, Attributes = selection.Settings.UseDataAnnotations ? new List <MetadataAttribute> { new MetadataAttribute("ForeignKey", string.Format("\"{0}\"", string.Join(",", foreignKey.Key))) } : null }); }
public static string GetEntityName(this EntityFrameworkCoreProject project, IDbObject dbObject) => project.CodeNamingConvention.GetClassName(dbObject.Name);
internal static void ScaffoldDbContext(EntityFrameworkCoreProject project) { var projectSelection = project.GlobalSelection(); project.Scaffold(project.GetDbContextClassDefinition(projectSelection, false), project.GetDataLayerDirectory()); }
public static string GetPluralName(this EntityFrameworkCoreProject project, IDbObject dbObject) => project.NamingService.Pluralize(project.GetEntityName(dbObject));
internal static void ScaffoldRepositoryInterface(EntityFrameworkCoreProject project) { project.Scaffold(project.GetRepositoryInterfaceDefinition(), project.GetDataLayerContractsDirectory()); }
public static string GetDbSetPropertyName(this EntityFrameworkCoreProject project, IDbObject dbObject, bool pluralize) => pluralize?project.NamingService.Pluralize(project.GetEntityName(dbObject)) : project.GetEntityName(dbObject);
internal static void ScaffoldBaseRepositoryClassDefinition(EntityFrameworkCoreProject project) { project.Scaffold(project.GetRepositoryBaseClassDefinition(), project.GetDataLayerRepositoriesDirectory()); }
public static string GetEntityConfigurationName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Format("{0}Configuration", project.GetEntityName(dbObject));
internal static void ScaffoldRepositoryExtensionsClassDefinition(EntityFrameworkCoreProject project) { project.Scaffold(project.GetPagingExtensionsClassDefinition(false), project.GetDataLayerRepositoriesDirectory()); }
public static string GetFullEntityName(this EntityFrameworkCoreProject project, IDbObject dbObject) => string.Join(".", project.CodeNamingConvention.GetNamespace(project.ProjectNamespaces.EntityLayer), project.CodeNamingConvention.GetClassName(dbObject.Schema), project.CodeNamingConvention.GetClassName(dbObject.Name));
private static void ScaffoldRepositoryInterface(EntityFrameworkCoreProject project) => CSharpCodeBuilder.CreateFiles(project.OutputDirectory, project.GetDataLayerContractsDirectory(), project.GlobalSelection().Settings.ForceOverwrite, project.GetRepositoryInterfaceDefinition());