public When_Type_Is_One_Degree_Removed_From_Owning_Type() { var domain = TestUtil.CreateTestDomain(new MockFileSystem()); var orderType = domain.Types.Single(t => t.Name == "order"); adapter = new DbTypeAdapter(orderType, null, OperationType.None, domain); }
private CodeFile GenerateInsertFunction(ApplicationType applicationType, Domain domain) { var adapter = new DbTypeAdapter(applicationType, "insert", OperationType.Insert, domain); if (adapter.AddMany) { return(GenerateTemplateFromAdapter(adapter, DbTemplates.InsertMany)); } else { return(GenerateTemplateFromAdapter(adapter, DbTemplates.Insert)); } }
private CodeFile GenerateTemplateFromAdapter(DbTypeAdapter adapter, string templateName) { try { return(new CodeFile { Name = adapter.FunctionName + SqlExtension, Contents = Util.GetCompiledTemplate(templateName)(adapter), RelativePath = ".\\" + adapter.Name + "\\" }); } catch (Exception ex) { throw new InvalidOperationException($"Unable to generate template {templateName} for type {adapter.Name}", ex); } }
private CodeFile GenerateSoftDeleteFunction(ApplicationType type, Domain domain) { var adapter = new DbTypeAdapter(type, DeleteOperationName, OperationType.Delete, domain); return(GenerateTemplateFromAdapter(adapter, DbTemplates.DeleteSoft)); }
private CodeFile GenerateInsertType(ApplicationType applicationType, Domain domain) { var adapter = new DbTypeAdapter(applicationType, "new", OperationType.Insert, domain); return(GenerateTemplateFromAdapter(adapter, "InsertType")); }
private CodeFile GenerateResultType(ApplicationType applicationType, Domain domain) { var adapter = new DbTypeAdapter(applicationType, "result", OperationType.None, domain); return(GenerateTemplateFromAdapter(adapter, "ResultType")); }
private CodeFile GenerateSelectAllFunction(ApplicationType applicationType, Domain domain) { var adapter = new DbTypeAdapter(applicationType, "select_all", OperationType.Select, domain); return(GenerateTemplateFromAdapter(adapter, "SelectAllTemplate")); }
public List <CodeFile> Generate(Domain domain, Settings settings) { Util.RegisterHelpers(domain.TypeProvider); var files = new List <CodeFile>(); var skipPolicyGeneration = domain.UserType == null; if (skipPolicyGeneration) { Log.Warning("Skipping security policy generation because no domain user type is defined"); } foreach (var type in domain.FilteredTypes) { if (!type.Ignore) { if (settings.GenerateSecurityPolicies && type.Attributes?.createPolicy != false && !skipPolicyGeneration) { files.Add(GenerateSecurityPoicy(type, domain)); } var adapter = new DbTypeAdapter(type, UpdateFunctionName, OperationType.Update, domain); if (adapter.HasExcludedFields) { files.Add(GenerateResultType(type, domain)); } if (adapter.UsesCustomInsertType && !domain.TypeProvider.CustomTypeExists(adapter.NewTypeName)) { files.Add(GenerateInsertType(type, domain)); } files.Add(GenerateInsertFunction(type, domain)); files.Add(GenerateDisplayType(type, domain)); files.Add(GenerateSelectAllFunction(type, domain)); files.Add(GenerateSelectAllForDisplayFunction(type, domain)); if (type.Paged) { files.Add(GeneratePagedOrderedSelectFunction(type, domain)); files.Add(GenerateSelectPagedForDisplayFunction(type, domain)); } if (adapter.UpdateFields.Any()) { files.Add(GenerateUpdateFunction(adapter)); } if (type.Fields.Count(f => f.IsIdentity) == 1) { var identityField = type.Fields.FirstOrDefault(f => f.IsIdentity); if (identityField != null) { files.Add(GenerateSelectByPrimaryKeyFunction(type, identityField, domain)); files.Add(GenerateSelectAllForDisplayByRelatedTypeFunction(type, identityField, domain)); } } if (type.Fields.Any(f => f.ReferencesType != null)) { foreach (var field in type.Fields.Where(f => f.ReferencesType != null)) { files.Add(GenerateSelectByRelatedTypeFunction(type, field, domain)); files.Add(GenerateSelectAllForDisplayByRelatedTypeFunction(type, field, domain)); if (type.Paged) { files.Add(GeneratePagedSelectByRelatedTypeFunction(type, field, domain)); files.Add(GeneratePagedSelectForDisplayByRelatedTypeFunction(type, field, domain)); } } } if (type.Constraints.Any()) { foreach (var constraint in type.Constraints) { files.Add(GenerateSelectByConstraint(type, constraint, domain)); } } if (type.DeleteType == DeleteType.Hard) { files.Add(GenerateDeleteFunction(type, domain)); } if (type.DeleteType == DeleteType.Soft) { files.Add(GenerateSoftDeleteFunction(type, domain)); } if (type.Fields.Any(f => f.IsSearch)) { files.Add(GenerateSearchFunction(type, domain)); } if (!type.IsSecurityPrincipal) { // find all the link types that reference this type var linkTypesReferencingCurrentType = domain.FilteredTypes.Where(t => t.IsLink && t.Fields.Any(f => f.HasReferenceType && f.ReferencesType == type)); if (linkTypesReferencingCurrentType.Any()) { foreach (var linkingType in linkTypesReferencingCurrentType) { var linkAdapter = new SelectForDisplayViaLinkDbTypeAdapter(type, SelectAllForDisplayFunctionName, linkingType, domain); if (linkAdapter.LinkingTypeField != null && linkAdapter.LinkTypeOtherField != null) { files.Add(GenerateTemplateFromAdapter(linkAdapter, "SelectAllForDisplayViaLinkTemplate")); if (type.Paged) { var pagedLinkAdapter = new SelectPagedForDisplayViaLinkDbTypeAdapter(type, SelectAllForDisplayFunctionName, linkingType, domain); files.Add(GenerateTemplateFromAdapter(pagedLinkAdapter, "SelectPagedForDisplayViaLink")); } } } } } } } return(files); }
private CodeFile GenerateUpdateFunction(DbTypeAdapter adapter) { return(GenerateTemplateFromAdapter(adapter, DbTemplates.Update)); }