コード例 #1
0
        public void ApplyMapping(ConventionModelMapper mapper)
        {
            mapper.Class <TicketRelationship>(map => {
                map.ManyToOne(x => x.PrimaryTicket, propMap => {
                    propMap.Column(nameFormatter.GetForeignKeyColumnName(Reflect.Property <TicketRelationship>(x => x.PrimaryTicket)));
                    propMap.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <TicketRelationship>(x => x.PrimaryTicket), typeof(TicketRelationship)));
                    propMap.Index(nameFormatter.GetIndexName(typeof(TicketRelationship), Reflect.Property <TicketRelationship>(x => x.PrimaryTicket)));
                    propMap.Cascade(Cascade.Persist);
                });

                map.ManyToOne(x => x.SecondaryTicket, propMap => {
                    propMap.Column(nameFormatter.GetForeignKeyColumnName(Reflect.Property <TicketRelationship>(x => x.SecondaryTicket)));
                    propMap.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <TicketRelationship>(x => x.SecondaryTicket), typeof(TicketRelationship)));
                    propMap.Index(nameFormatter.GetIndexName(typeof(TicketRelationship), Reflect.Property <TicketRelationship>(x => x.SecondaryTicket)));
                    propMap.Cascade(Cascade.Persist);
                });
            });
        }
コード例 #2
0
ファイル: ManyToOneMapping.cs プロジェクト: csf-dev/agiil
        public void ApplyMapping(ConventionModelMapper mapper)
        {
            mapper.BeforeMapManyToOne += (modelInspector, member, propertyCustomizer) => {
                var parentType = member.LocalMember.GetPropertyOrFieldType();
                var childType  = member.LocalMember.ReflectedType;

                propertyCustomizer.Column(formatter.GetIdentityColumnName(parentType));
                propertyCustomizer.ForeignKey(formatter.GetForeignKeyConstraintName(parentType, childType));
                propertyCustomizer.Index(formatter.GetIndexName(childType, parentType));
                propertyCustomizer.Cascade(Cascade.Persist);
            };
        }
コード例 #3
0
ファイル: UserMapping.cs プロジェクト: csf-dev/agiil
        public void ApplyMapping(ConventionModelMapper mapper)
        {
            mapper.Class <User>(map => {
                map.Set(x => x.ContributorTo, set => {
                    set.Key(key => {
                        key.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <Project>(x => x.Contributors), typeof(Project)));
                    });
                    set.Table(nameFormatter.GetManyToManyTableName(typeof(Project), Contributor, typeof(User)));
                }, r => r.ManyToMany(mtm => {
                    mtm.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <User>(x => x.ContributorTo), typeof(User)));
                }));

                map.Set(x => x.AdministratorOf, set => {
                    set.Key(key => {
                        key.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <Project>(x => x.Administrators), typeof(Project)));
                    });
                    set.Table(nameFormatter.GetManyToManyTableName(typeof(Project), Administrator, typeof(User)));
                }, r => r.ManyToMany(mtm => {
                    mtm.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <User>(x => x.AdministratorOf), typeof(User)));
                }));
            });
        }
コード例 #4
0
ファイル: TicketMapping.cs プロジェクト: csf-dev/agiil
        public void ApplyMapping(ConventionModelMapper mapper)
        {
            mapper.Class <Ticket>(map => {
                map.Set(x => x.PrimaryRelationships, set => {
                    set.Key(k => {
                        var participant = RelationshipParticipant.Primary.ToString();
                        var member      = nameof(Ticket);

                        k.Column(nameFormatter.GetForeignKeyColumnName(participant, member));
                        k.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <TicketRelationship>(x => x.PrimaryTicket), typeof(TicketRelationship)));
                    });
                });

                map.Set(x => x.SecondaryRelationships, set => {
                    set.Key(k => {
                        var participant = RelationshipParticipant.Secondary.ToString();
                        var member      = nameof(Ticket);

                        k.Column(nameFormatter.GetForeignKeyColumnName(participant, member));
                        k.ForeignKey(nameFormatter.GetForeignKeyConstraintName(Reflect.Property <TicketRelationship>(x => x.SecondaryTicket), typeof(TicketRelationship)));
                    });
                });
            });
        }
コード例 #5
0
ファイル: ManyToManyMapping.cs プロジェクト: csf-dev/agiil
        public void ApplyMapping(ConventionModelMapper mapper)
        {
            mapper.IsManyToMany((member, declared) => {
                var property = member as PropertyInfo;

                if (property == null || !property.CanRead)
                {
                    return(false);
                }

                if (property.GetCustomAttribute <ManyToManyAttribute>() != null)
                {
                    return(true);
                }

                return(false);
            });

            mapper.BeforeMapSet += (modelInspector, propertyPath, propertyCustomizer) => {
                var manyToManyAttrib = propertyPath.LocalMember.GetCustomAttribute <ManyToManyAttribute>();
                if (manyToManyAttrib == null)
                {
                    return;
                }

                if (manyToManyAttrib.IsActiveSide)
                {
                    propertyCustomizer.Cascade(Cascade.Persist);
                    propertyCustomizer.Inverse(false);
                }
                else
                {
                    propertyCustomizer.Cascade(Cascade.None);
                    propertyCustomizer.Inverse(true);
                }

                propertyCustomizer.Access(typeof(SourceCollectionAccessor));

                var activeEntityType   = GetActiveType(propertyPath.LocalMember, manyToManyAttrib.IsActiveSide);
                var inactiveEntityType = GetInactiveType(propertyPath.LocalMember, manyToManyAttrib.IsActiveSide);

                propertyCustomizer.Table(formatter.GetManyToManyTableName(activeEntityType, inactiveEntityType));

                propertyCustomizer.Key(keyMap => {
                    var parentType = GetDeclaringType(propertyPath.LocalMember);
                    var childType  = GetCollectionType(propertyPath.LocalMember);

                    var columnName = formatter.GetIdentityColumnName(parentType);
                    var fkName     = formatter.GetForeignKeyConstraintName(activeEntityType, inactiveEntityType);

                    keyMap.Column(columnName);
                    keyMap.ForeignKey(fkName);
                });
            };

            mapper.BeforeMapManyToMany += (modelInspector, propertyPath, collectionRelationManyToManyCustomizer) => {
                var myType       = GetDeclaringType(propertyPath.LocalMember);
                var oppositeType = GetCollectionType(propertyPath.LocalMember);

                collectionRelationManyToManyCustomizer.Column(formatter.GetIdentityColumnName(oppositeType));
                collectionRelationManyToManyCustomizer.ForeignKey(formatter.GetForeignKeyConstraintName(oppositeType, myType));
            };
        }
コード例 #6
0
ファイル: OneToManyMapping.cs プロジェクト: csf-dev/agiil
        public void ApplyMapping(ConventionModelMapper mapper)
        {
            mapper.IsOneToMany((member, isDeclared) => {
                if (isDeclared)
                {
                    return(true);
                }

                return(member.GetCustomAttribute <ManyToManyAttribute>() == null);
            });

            mapper.IsSet((member, isDeclared) => {
                if (isDeclared)
                {
                    return(true);
                }

                var prop = member as PropertyInfo;

                if (prop == null || !prop.CanRead)
                {
                    return(false);
                }

                var propertyType = prop.PropertyType;

                if (!propertyType.IsGenericType || propertyType.GetGenericTypeDefinition() != typeof(ISet <>))
                {
                    return(false);
                }

                if (!typeof(IEntity).IsAssignableFrom(propertyType.GetGenericArguments()[0]))
                {
                    return(false);
                }

                return(true);
            });

            mapper.BeforeMapSet += (modelInspector, propertyPath, propertyCustomizer) => {
                if (propertyPath.LocalMember.GetCustomAttribute <ManyToManyAttribute>() != null)
                {
                    return;
                }

                propertyCustomizer.Cascade(Cascade.All | Cascade.DeleteOrphans);
                propertyCustomizer.Access(typeof(SourceCollectionAccessor));

                propertyCustomizer.Key(keyMap => {
                    var parentType = propertyPath.LocalMember.DeclaringType;
                    var childType  = propertyPath.LocalMember.GetPropertyOrFieldType().GetGenericArguments()[0];

                    var columnName = formatter.GetIdentityColumnName(parentType);
                    var fkName     = formatter.GetForeignKeyConstraintName(parentType, childType);

                    keyMap.Column(columnName);
                    keyMap.ForeignKey(fkName);
                });

                propertyCustomizer.Inverse(true);
            };
        }