コード例 #1
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var softDelete = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            var createDate = new AttributeToTableAnnotationConvention <CreateDateAttribute, string>(
                "CreateDateColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            var updateDate = new AttributeToTableAnnotationConvention <UpdateDateAttribute, string>(
                "UpdateDateColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(softDelete);
            modelBuilder.Conventions.Add(createDate);
            modelBuilder.Conventions.Add(updateDate);

            modelBuilder.Entity <User>().Map(m => m.ToTable("Users"));

            modelBuilder.Entity <User>()
            .Property(p => p.UserName).HasMaxLength(50)
            .HasColumnAnnotation(
                IndexAnnotation.AnnotationName,
                new IndexAnnotation(new IndexAttribute("UserNameIndex", 1)
            {
                IsUnique = false
            }));

            modelBuilder.Entity <Role>().Map(m => m.ToTable("Roles"));
            modelBuilder.Entity <UserRole>().Map(m => m.ToTable("UserRoles"));
            modelBuilder.Entity <UserLogin>().Map(m => m.ToTable("UserLogins"));
            modelBuilder.Entity <UserClaim>().Map(m => m.ToTable("UserClaims"));
            modelBuilder.Entity <Permission>().Map(m => m.ToTable("Permissions"));
        }
コード例 #2
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            // Conventions
            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            var userAwareConvention = new AttributeToTableAnnotationConvention <UserAwareAttribute, string>(
                UserAwareAttribute.UserAnnotation, (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(userAwareConvention);

            // Table names
            modelBuilder.Entity <User>().ToTable("User");
            modelBuilder.Entity <UserClaim>().ToTable("UserClaim");
            modelBuilder.Entity <UserLogin>().ToTable("UserLogin");
            modelBuilder.Entity <UserRole>().ToTable("UserRole");
            modelBuilder.Entity <Role>().ToTable("Role");

            // Cascade deletes
            modelBuilder.Entity <ElementCell>()
            .HasRequired(item => item.ElementField)
            .WithMany(item => item.ElementCellSet)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <UserElementField>()
            .HasRequired(item => item.User)
            .WithMany(item => item.UserElementFieldSet)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <UserElementCell>()
            .HasRequired(item => item.User)
            .WithMany(item => item.UserElementCellSet)
            .WillCascadeOnDelete(false);
        }
コード例 #3
0
ファイル: IdentityModels.cs プロジェクト: rioka/EfMultitenant
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity <ProductCategory>()
            .HasRequired(pc => pc.User)
            .WithMany()
            .HasForeignKey(pc => pc.TenantId)
            .WillCascadeOnDelete(false);

            modelBuilder.Entity <Product>()
            .HasRequired(p => p.User)
            .WithMany()
            .HasForeignKey(p => p.TenantId)
            .WillCascadeOnDelete(false);
            modelBuilder.Entity <Product>()
            .HasRequired(p => p.Category)
            .WithMany()
            .HasForeignKey(p => p.CategoryId)
            .WillCascadeOnDelete(false);

            var conv =
                new AttributeToTableAnnotationConvention <TenantAwareAttribute, string>(
                    TenantAwareAttribute.TenantAnnotation, (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #4
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            // ConfigureIsDeleted(modelBuilder);

            modelBuilder.Entity <Address>()
            .HasRequired(a => a.Person)
            .WithMany(x => x.Addresses)
            .HasForeignKey(a => a.PersonId)
            .WillCascadeOnDelete(false);

            var convention = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(convention);

            //modelBuilder.Entity<Person>()
            //    .Property(e => e.RowVersion)
            //    .IsConcurrencyToken()
            //    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            //modelBuilder.Entity<Address>()
            //    .Property(e => e.RowVersion)
            //    .IsConcurrencyToken()
            //    .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
        }
コード例 #5
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            var convention = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(convention);
        }
コード例 #6
0
        public static void AddSoftDeleteConvention(this DbModelBuilder modelBuilder)
        {
            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #7
0
        public void Register(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new NoteConfiguration());

            // register multitenancy
            var conv =
                new AttributeToTableAnnotationConvention <TenantAttribute, string>(
                    MultitenancyConstants.TenantAnnotation, (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #8
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.AddFromAssembly(typeof(ApplicationContext).Assembly);

            base.OnModelCreating(modelBuilder);
			var conv = new AttributeToTableAnnotationConvention<SoftDeleteAttibute, string>(
				"SoftDeleteColumnName",
				(type, attributes) => attributes.Single().ColumnName);
	        modelBuilder.Conventions.Add(conv);


        }
コード例 #9
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Registration>().ToTable("Registration");
            modelBuilder.Entity <Attendee>().ToTable("Attendee");

            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>("SoftDeleteColumnName",
                                                                                              (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);

            base.OnModelCreating(modelBuilder);
        }
コード例 #10
0
ファイル: BillingContext.cs プロジェクト: drveni92/echo
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove <ManyToManyCascadeDeleteConvention>();
            modelBuilder.Conventions.Remove <OneToManyCascadeDeleteConvention>();

            modelBuilder.Ignore <Basic>();

            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #11
0
        public static void RegisterAnnotationConventions(ref DbModelBuilder modelBuilder)
        {
            var conv = new AttributeToTableAnnotationConvention <EntityFramework.SoftDeleteAttribute, string>(
                SoftDeleteAttribute.SoftDeleteAnnotation,
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);

            var conv2 = new AttributeToTableAnnotationConvention <EntityFramework.TenantAwareAttribute, string>(
                TenantAwareAttribute.TenantAwareAnnotation,
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv2);
        }
コード例 #12
0
ファイル: EntityContext.cs プロジェクト: Xeloss/Mokona
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <User>()
            .HasMany <Role>(u => u.Roles)
            .WithMany();

            var convention = new AttributeToTableAnnotationConvention <SoftDeletableAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(convention);

            base.OnModelCreating(modelBuilder);
        }
コード例 #13
0
ファイル: ShopContext.cs プロジェクト: gkrupkowski/SoftDelete
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove <MaxLengthAttributeConvention>();
            modelBuilder.Properties <string>().
            Configure(s => s.HasMaxLength(50));
            modelBuilder.Conventions.Add <PrimaryKeyConvention>();
            modelBuilder.Conventions.Add <HideColumnNameConvention>();


            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #14
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Listing>()
                .HasRequired(l => l.SellingAgent)
                .WithMany(a => a.Listings)
                .HasForeignKey(a => a.SellingAgentId);

            modelBuilder.Entity<ListingPhoto>()
                .ToTable("ListingPhoto");

            var conv = new AttributeToTableAnnotationConvention<SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #15
0
ファイル: BacklogContext.cs プロジェクト: cDoru/backlog
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Article>().
            HasMany(u => u.Tags).
            WithMany(r => r.Articles).
            Map(
                m =>
            {
                m.MapLeftKey("Article_Id");
                m.MapRightKey("Tag_Id");
                m.ToTable("ArticleTags");
            });

            modelBuilder.Entity <Article>().
            HasMany(u => u.Categories).
            WithMany(r => r.Articles).
            Map(
                m =>
            {
                m.MapLeftKey("Article_Id");
                m.MapRightKey("Category_Id");
                m.ToTable("ArticleCategories");
            });

            modelBuilder.Entity <User>().
            HasMany(u => u.Roles).
            WithMany(r => r.Users).
            Map(
                m =>
            {
                m.MapLeftKey("User_Id");
                m.MapRightKey("Role_Id");
                m.ToTable("UserRoles");
            });

            modelBuilder.Entity <User>()
            .HasOptional(u => u.Profile)
            .WithRequired(p => p.User);

            var convention = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(convention);
        }
コード例 #16
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Configurations.Add(new MovieConfiguration());
            modelBuilder.Configurations.Add(new GenreConfiguration());
            modelBuilder.Configurations.Add(new ProductionCompanyConfiguration());
            modelBuilder.Configurations.Add(new CharacterConfiguration());
            modelBuilder.Configurations.Add(new ActorConfiguration());
            modelBuilder.Configurations.Add(new MovieGenreConfiguration());
            modelBuilder.Configurations.Add(new ProductionCompanyMovieConfiguration());
            modelBuilder.Configurations.Add(new MovieStatusConfiguration());

            var conv = new AttributeToTableAnnotationConvention<SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #17
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            modelBuilder.Entity <Course>()
            .HasMany(c => c.Instructors).WithMany(i => i.Courses)
            .Map(t => t.MapLeftKey("CourseID")
                 .MapRightKey("InstructorID")
                 .ToTable("CourseInstructor"));

            modelBuilder.Entity <Department>().MapToStoredProcedures();

            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #18
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Course>()
                .HasMany(c => c.Instructors).WithMany(i => i.Courses)
                .Map(t => t.MapLeftKey("CourseID")
                    .MapRightKey("InstructorID")
                    .ToTable("CourseInstructor"));

            modelBuilder.Entity<Department>().MapToStoredProcedures();

            var conv = new AttributeToTableAnnotationConvention<SoftDeleteAttribute, string>(
               "SoftDeleteColumnName",
               (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #19
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            modelBuilder.Configurations.Add(new MovieConfiguration());
            modelBuilder.Configurations.Add(new GenreConfiguration());
            modelBuilder.Configurations.Add(new ProductionCompanyConfiguration());
            modelBuilder.Configurations.Add(new CharacterConfiguration());
            modelBuilder.Configurations.Add(new ActorConfiguration());
            modelBuilder.Configurations.Add(new MovieGenreConfiguration());
            modelBuilder.Configurations.Add(new ProductionCompanyMovieConfiguration());
            modelBuilder.Configurations.Add(new MovieStatusConfiguration());

            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #20
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity <User>().
            HasMany(u => u.Roles).
            WithMany(r => r.Users).
            Map(
                m =>
            {
                m.MapLeftKey("User_Id");
                m.MapRightKey("Role_Id");
                m.ToTable("UserRoles");
            });

            var convention = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(convention);
        }
コード例 #21
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            #region apply the custom mapping rules for each column of the tables.

            /*
             * TODO: the statement of the rules of other tables.
             */
            modelBuilder.Configurations.Add(new ModuleMapper());
            modelBuilder.Configurations.Add(new UserMapper());
            modelBuilder.Configurations.Add(new DepartmentMapper());
            modelBuilder.Configurations.Add(new EmployeeBankMapper());
            modelBuilder.Configurations.Add(new CloudFolderMapper());

            //分表

            /*
             * modelBuilder.Entity<User>()
             *  .HasKey(t => t.ID);
             *
             * modelBuilder.Entity<Employee>()
             *  .HasKey(t => t.ID);
             *
             * modelBuilder.Entity<Employee>()
             *  .HasRequired(t => t.User)
             *  .WithRequiredPrincipal(t => t.Employee);
             */
            #endregion

            modelBuilder.Entity <BudgetTemplateSpace>().Property(item => item.Amount).HasPrecision(18, 2);
            modelBuilder.Entity <BudgetTemplateSpace>().Property(item => item.Size).HasPrecision(4, 1);

            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            var conv = new AttributeToTableAnnotationConvention <TenantAwareAttribute, string>(
                TenantAwareAttribute.TenantAnnotation, (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);

            //DbInterception.Add()
            base.OnModelCreating(modelBuilder);
        }
コード例 #22
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Map using TPT - this makes soft delete more complicated since not
            // all tables have the IsDeleted column
            modelBuilder.Entity<Listing>().ToTable("dbo.Listings");
            modelBuilder.Entity<CommercialListing>().ToTable("dbo.CommercialListings");

            modelBuilder.Entity<Listing>()
                .HasRequired(l => l.SellingAgent)
                .WithMany(a => a.Listings)
                .HasForeignKey(a => a.SellingAgentId);

            modelBuilder.Entity<ListingPhoto>()
                .ToTable("ListingPhoto");

            var conv = new AttributeToTableAnnotationConvention<SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }
コード例 #23
0
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // Map using TPT - this makes soft delete more complicated since not
            // all tables have the IsDeleted column
            modelBuilder.Entity <Listing>().ToTable("dbo.Listings");
            modelBuilder.Entity <CommercialListing>().ToTable("dbo.CommercialListings");

            modelBuilder.Entity <Listing>()
            .HasRequired(l => l.SellingAgent)
            .WithMany(a => a.Listings)
            .HasForeignKey(a => a.SellingAgentId);

            modelBuilder.Entity <ListingPhoto>()
            .ToTable("ListingPhoto");

            var conv = new AttributeToTableAnnotationConvention <SoftDeleteAttribute, string>(
                "SoftDeleteColumnName",
                (type, attributes) => attributes.Single().ColumnName);

            modelBuilder.Conventions.Add(conv);
        }