protected override void OnModelCreating(ModelBuilder builder)
        {
            //filtering all unapproved photos from response
            builder.Entity <Photo>().HasQueryFilter(p => p.IsApproved);

            base.OnModelCreating(builder);

            builder.Entity <UserRole>(UserRole => {
                UserRole.HasKey(ur => new { ur.UserId, ur.RoleId });
                UserRole.HasOne(ur => ur.Role).WithMany(r => r.UserRoles).HasForeignKey(ur => ur.RoleId).IsRequired();
                UserRole.HasOne(ur => ur.User).WithMany(r => r.UserRoles).HasForeignKey(ur => ur.UserId).IsRequired();
            });

            builder.Entity <Like>()
            .HasKey(k => new { k.LikerId, k.LikeeId });

            builder.Entity <Like>()
            .HasOne(u => u.Likee).WithMany(u => u.Liker).HasForeignKey(u => u.LikeeId).OnDelete(DeleteBehavior.Restrict);
            builder.Entity <Like>()
            .HasOne(u => u.Liker).WithMany(u => u.Likees).HasForeignKey(u => u.LikerId).OnDelete(DeleteBehavior.Restrict);

            builder.Entity <Message>()
            .HasOne(u => u.Sender).WithMany(m => m.MessagesSent).OnDelete(DeleteBehavior.Restrict);
            builder.Entity <Message>()
            .HasOne(u => u.Recipient).WithMany(m => m.MessagesReceived).OnDelete(DeleteBehavior.Restrict);
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity <UserRole>(UserRole =>
            {
                UserRole.HasKey(ur => new { ur.RoleId, ur.UserId });
                UserRole.HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId)
                .IsRequired();
                UserRole.HasOne(ur => ur.User)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .IsRequired();
            });
        }
Exemple #3
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity <UserRole>(UserRole =>
            {
                UserRole.HasKey(ur => new { ur.UserId, ur.RoleId });

                UserRole.HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId)
                .IsRequired();

                UserRole.HasOne(ur => ur.User)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .IsRequired();
            });



            builder.Entity <Like>()
            .HasKey(k => new { k.LikerID, k.LikeeID });

            builder.Entity <Like>()
            .HasOne(u => u.Likee)
            .WithMany(u => u.Likers)
            .HasForeignKey(u => u.LikeeID)
            .OnDelete(DeleteBehavior.Restrict);

            builder.Entity <Like>()
            .HasOne(u => u.Liker)
            .WithMany(u => u.Likees)
            .HasForeignKey(u => u.LikerID)
            .OnDelete(DeleteBehavior.Restrict);

            builder.Entity <Message>()
            .HasOne(u => u.Sender)
            .WithMany(m => m.MessagesSent)
            .OnDelete(DeleteBehavior.Restrict);

            builder.Entity <Message>()
            .HasOne(u => u.Recipient)
            .WithMany(m => m.MessagesReceived)
            .OnDelete(DeleteBehavior.Restrict);
        }
Exemple #4
0
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity <UserRole>(UserRole => {
                UserRole.HasKey(ur => new { ur.UserId, ur.RoleId });

                UserRole.HasOne(ur => ur.Role)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.RoleId)
                .IsRequired();

                UserRole.HasOne(ur => ur.User)
                .WithMany(r => r.UserRoles)
                .HasForeignKey(ur => ur.UserId)
                .IsRequired();
            });
            ////Configure Users Table
            // builder.Entity<User>().ToTable("Users");
            // builder.Entity<User>().HasKey(x => x.Id);

            // builder.Entity<User>().Property(x => x.Id).IsRequired().ValueGeneratedOnAdd();

            // We have created a Primary key for likes
            builder.Entity <Like>()
            .HasKey(k => new { k.LikerId, k.LikeeId });

            // Creating One to Many Relation

            builder.Entity <Like>()
            .HasOne(u => u.Likee)
            .WithMany(u => u.Likers)
            .HasForeignKey(u => u.LikeeId)
            .OnDelete(deleteBehavior: DeleteBehavior.Restrict);

            builder.Entity <Like>()
            .HasOne(u => u.Liker)
            .WithMany(u => u.Likees)
            .HasForeignKey(u => u.LikerId)
            .OnDelete(deleteBehavior: DeleteBehavior.Restrict);

            // // We are creating Primary key for the user Messages
            // builder.Entity<Message>()
            //         .HasKey(m => new { m.SenderId, m.RecipientId });

            builder.Entity <Message>()
            .Property(x => x.Id).IsRequired()
            .ValueGeneratedOnAdd();

            // I'm creating many to many RelationShip
            builder.Entity <Message>()
            .HasOne(m => m.Sender)
            .WithMany(m => m.MessagesSent)
            .HasForeignKey(m => m.SenderId)
            .OnDelete(deleteBehavior: DeleteBehavior.Restrict);

            builder.Entity <Message>()
            .HasOne(m => m.Recipient)
            .WithMany(m => m.MessagesReceived)
            .HasForeignKey(m => m.RecipientId)
            .OnDelete(deleteBehavior: DeleteBehavior.Restrict);
        }