public RouteModel GetNavigationRoute()
        {
            var module = new ComponentModel((IElement)Element).Module;
            var otherEndModule = new ComponentModel((IElement)_associationEnd.OtherEnd().Element).Module;
            var modulesToCheck = new[] { otherEndModule, module }.Concat(module.GetParentFolders().OfType <ModuleModel>()).ToList();
            var routes = modulesToCheck.SelectMany(x => x.Routing?.Routes ?? new List <RouteModel>()).ToList();
            var route  = routes.FirstOrDefault(x => x.TypeReference.Element.Id == Element.Id);

            return(route);
        }
Exemplo n.º 2
0
        public static RelationshipType Relationship(this IAssociationEnd associationEnd)
        {
            if ((associationEnd.Multiplicity == Multiplicity.One || associationEnd.Multiplicity == Multiplicity.ZeroToOne) && (associationEnd.OtherEnd().Multiplicity == Multiplicity.One || associationEnd.OtherEnd().Multiplicity == Multiplicity.ZeroToOne))
            {
                return(RelationshipType.OneToOne);
            }
            if ((associationEnd.Multiplicity == Multiplicity.One || associationEnd.Multiplicity == Multiplicity.ZeroToOne) && associationEnd.OtherEnd().Multiplicity == Multiplicity.Many)
            {
                return(RelationshipType.OneToMany);
            }
            if (associationEnd.Multiplicity == Multiplicity.Many && (associationEnd.OtherEnd().Multiplicity == Multiplicity.One || associationEnd.OtherEnd().Multiplicity == Multiplicity.ZeroToOne))
            {
                return(RelationshipType.ManyToOne);
            }
            if (associationEnd.Multiplicity == Multiplicity.Many && associationEnd.OtherEnd().Multiplicity == Multiplicity.Many)
            {
                return(RelationshipType.ManyToMany);
            }

            throw new Exception(string.Format("The relationship type from [{0}] to [{1}] could not be determined.", associationEnd.Class.Name, associationEnd.OtherEnd().Class.Name));
        }
Exemplo n.º 3
0
        public override string PropertyBefore(IAssociationEnd associationEnd)
        {
            if (associationEnd.RequiresForeignKey())
            {
                if (associationEnd.OtherEnd().HasStereotype("Foreign Key"))
                {
                    return(base.PropertyBefore(associationEnd));
                }
                return($@"       {_foreignKeyType}{ (associationEnd.IsNullable ? "?" : "") } { associationEnd.Name().ToPascalCase() }Id {{ get; }}
");
            }
            return(base.PropertyBefore(associationEnd));
        }
        public override string AssociationAfter(IAssociationEnd associationEnd)
        {
            if (!associationEnd.IsNavigable)
            {
                return(base.AssociationBefore(associationEnd));
            }

            var t = ClassTypeSource.InProject(Template.Project, DomainEntityInterfaceTemplate.Identifier, nameof(IEnumerable));

            return($@"
        {t.GetClassType(associationEnd)} I{associationEnd.OtherEnd().Class.Name}.{associationEnd.Name().ToPascalCase()} => {associationEnd.Name().ToPascalCase()};
");
        }
Exemplo n.º 5
0
        private string GetForeignKeyLambda(IAssociationEnd associationEnd)
        {
            var columns = associationEnd.GetStereotypeProperty("Foreign Key", "Column Name", associationEnd.OtherEnd().Name().ToPascalCase() + "Id")
                          .Split(',')
                          .Select(x => x.Trim())
                          .ToList();

            if (columns.Count() == 1)
            {
                return($"x => x.{columns.Single()}");
            }
            return($"x => new {{ {string.Join(", ", columns.Select(x => "x."+ x))}}}");
        }
        public override string AssociationBefore(IAssociationEnd associationEnd)
        {
            if (!associationEnd.IsNavigable && associationEnd.Multiplicity == Multiplicity.One && associationEnd.OtherEnd().Multiplicity == Multiplicity.Many)
            {
                return($@"       public virtual { Template.Types.Get(associationEnd) } { associationEnd.Name() } {{ get; set; }}
");
            }
            return(base.AssociationBefore(associationEnd));
        }
Exemplo n.º 7
0
        public void MapOneToOne(IAssociationEnd associationEnd)
        {
            var parent = associationEnd.Association.SourceEnd;
            var child  = associationEnd.Association.TargetEnd;

            string hasClause  = associationEnd.MinMultiplicity != "0" ? "HasRequired" : "HasOptional";
            string withClause = "With" + (associationEnd.OtherEnd().MinMultiplicity != "0" ? "Required" : "Optional") + ((associationEnd.MinMultiplicity != "0") == (associationEnd.OtherEnd().MinMultiplicity != "0") ?  DeterminePrinciple(associationEnd)  : "");


        #line default
        #line hidden

        #line 207 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("            ");


        #line default
        #line hidden

        #line 208 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Format("this.{0}(x => x.{1})", hasClause, associationEnd.Name().ToPascalCase())));


        #line default
        #line hidden

        #line 208 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("\r\n            ");


        #line default
        #line hidden

        #line 209 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Format(".{0}({1})", withClause, associationEnd.OtherEnd().IsNavigable ? "x => x." + associationEnd.OtherEnd().Name().ToPascalCase(): "")));


        #line default
        #line hidden

        #line 209 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("\r\n");


        #line default
        #line hidden

        #line 210 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            if ((associationEnd.Association.AssociationType == AssociationType.Composition && associationEnd.Association.RelationshipString() == "0..1->1") ||
                (associationEnd.Association.AssociationType == AssociationType.Aggregation && associationEnd.Association.RelationshipString() == "0..1->1")
                )
            {
        #line default
        #line hidden

        #line 213 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write("            .Map(m => m.MapKey(\"");


        #line default
        #line hidden

        #line 214 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(associationEnd.Name().ToPascalCase() + "Id"));


        #line default
        #line hidden

        #line 214 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write("\"))\r\n");


        #line default
        #line hidden

        #line 215 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            }

        #line default
        #line hidden

        #line 215 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("            ;\r\n");


        #line default
        #line hidden

        #line 217 "C:\Dev\Intent\IntentArchitect\Modules\Intent.Modules.EF\Templates\EFMapping\EFMappingTemplate.tt"
        }
Exemplo n.º 8
0
        public void MapOneToOne(IAssociationEnd associationEnd)
        {
            var parent = associationEnd.Association.SourceEnd;
            var child  = associationEnd.Association.TargetEnd;

            string hasClause  = associationEnd.MinMultiplicity != "0" ? "HasRequired" : "HasOptional";
            string withClause = "With" + (associationEnd.OtherEnd().MinMultiplicity != "0" ? "Required" : "Optional") + ((associationEnd.MinMultiplicity != "0") == (associationEnd.OtherEnd().MinMultiplicity != "0") ?  DeterminePrinciple(associationEnd)  : "");


        #line default
        #line hidden

        #line 232 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("            ");


        #line default
        #line hidden

        #line 233 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Format("this.{0}(x => x.{1})", hasClause, associationEnd.Name().ToPascalCase())));


        #line default
        #line hidden

        #line 233 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("\r\n            ");


        #line default
        #line hidden

        #line 234 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(string.Format(".{0}({1})", withClause, associationEnd.OtherEnd().IsNavigable ? "x => x." + associationEnd.OtherEnd().Name().ToPascalCase(): "")));


        #line default
        #line hidden

        #line 234 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("\r\n");


        #line default
        #line hidden

        #line 235 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            if (((associationEnd.Association.AssociationType == AssociationType.Composition && associationEnd.Association.RelationshipString() == "0..1->1") ||
                 (associationEnd.Association.AssociationType == AssociationType.Aggregation && associationEnd.Association.RelationshipString() == "0..1->1")) &&
                Model.Attributes.All(a => a.Name.ToPascalCase() != associationEnd.OtherEnd().GetStereotypeProperty("Foreign Key", "Column Name", associationEnd.Name().ToPascalCase() + "Id").ToPascalCase()))
            {
        #line default
        #line hidden

        #line 238 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write("            .Map(m => m.MapKey(\"");


        #line default
        #line hidden

        #line 239 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(associationEnd.OtherEnd().GetStereotypeProperty("Foreign Key", "Column Name", associationEnd.Name().ToPascalCase() + "Id")));


        #line default
        #line hidden

        #line 239 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write("\"))\r\n");


        #line default
        #line hidden

        #line 240 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            }

        #line default
        #line hidden

        #line 241 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            if (associationEnd.Association.AssociationType == AssociationType.Composition)
            {
        #line default
        #line hidden

        #line 241 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
                this.Write("\t\t\t.WillCascadeOnDelete()\r\n");


        #line default
        #line hidden

        #line 243 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            }

        #line default
        #line hidden

        #line 243 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
            this.Write("            ;\r\n");


        #line default
        #line hidden

        #line 245 "C:\Dev\Intent.Modules\Modules\Intent.Modules.EntityFramework\Templates\EFMapping\EFMappingTemplate.tt"
        }
Exemplo n.º 9
0
 private static bool IsManyToVariantsOfOne(IAssociationEnd associationEnd)
 {
     return((associationEnd.Multiplicity == Multiplicity.One || associationEnd.Multiplicity == Multiplicity.ZeroToOne) &&
            associationEnd.OtherEnd().Multiplicity == Multiplicity.Many);
 }
Exemplo n.º 10
0
 private static bool RequiresForeignKeyOnAssociatedEnd(IAssociationEnd associationEnd)
 {
     return(associationEnd.Multiplicity == Multiplicity.Many
            &&
            (associationEnd.Association.AssociationType == AssociationType.Composition || associationEnd.OtherEnd().IsNavigable));
 }