Browse Source

CmsKit - EfCore configuration of Blogs

pull/7596/head
enisn 6 years ago
parent
commit
8f29f3c267
  1. 7
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogConsts.cs
  2. 9
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs
  3. 3
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContext.cs
  4. 41
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

7
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogConsts.cs

@ -0,0 +1,7 @@
namespace Volo.CmsKit.Blogs
{
public class BlogConsts
{
public static int MaxNameLength { get; set; } = 64;
}
}

9
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Blogs/BlogPostConsts.cs

@ -0,0 +1,9 @@
namespace Volo.CmsKit.Blogs
{
public class BlogPostConsts
{
public static int MaxTitleLength { get; set; } = 256;
public static int MaxCoverImageUrlLength { get; set; } = 2048;
}
}

3
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContext.cs

@ -3,6 +3,7 @@ using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Contents;
using Volo.CmsKit.Domain.Volo.CmsKit.Blogs;
using Volo.CmsKit.Pages;
using Volo.CmsKit.Ratings;
using Volo.CmsKit.Reactions;
@ -22,6 +23,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
public DbSet<Tag> Tags { get; set; }
public DbSet<EntityTag> EntityTags { get; set; }
public DbSet<Page> Pages { get; set; }
public DbSet<Blog> Blogs { get; set; }
public DbSet<BlogPost> BlogPosts { get; set; }
public CmsKitDbContext(DbContextOptions<CmsKitDbContext> options)
: base(options)

41
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -13,6 +13,8 @@ using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Pages;
using Volo.CmsKit.Ratings;
using Volo.CmsKit.Tags;
using Volo.CmsKit.Domain.Volo.CmsKit.Blogs;
using Volo.CmsKit.Blogs;
namespace Volo.CmsKit.EntityFrameworkCore
{
@ -58,8 +60,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.EntityId).IsRequired().HasMaxLength(UserReactionConsts.MaxEntityIdLength);
b.Property(x => x.ReactionName).IsRequired().HasMaxLength(UserReactionConsts.MaxReactionNameLength);
b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId, x.ReactionName});
b.HasIndex(x => new {x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName});
b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.ReactionName });
b.HasIndex(x => new { x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName });
});
}
@ -76,8 +78,8 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.Text).IsRequired().HasMaxLength(CommentConsts.MaxTextLength);
b.Property(x => x.RepliedCommentId);
b.HasIndex(x => new {x.TenantId, x.EntityType, x.EntityId});
b.HasIndex(x => new {x.TenantId, x.RepliedCommentId});
b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId });
b.HasIndex(x => new { x.TenantId, x.RepliedCommentId });
});
}
@ -173,7 +175,7 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.EntityType).IsRequired().HasMaxLength(TagConsts.MaxEntityTypeLength);
b.Property(x => x.Name).IsRequired().HasMaxLength(TagConsts.MaxNameLength);
b.HasIndex(x => new {x.TenantId, x.Name});
b.HasIndex(x => new { x.TenantId, x.Name });
});
builder.Entity<EntityTag>(b =>
@ -182,12 +184,12 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.ConfigureByConvention();
b.HasKey(x => new {x.EntityId, x.TagId});
b.HasKey(x => new { x.EntityId, x.TagId });
b.Property(x => x.EntityId).IsRequired();
b.Property(x => x.TagId).IsRequired();
b.HasIndex(x => new {x.TenantId, x.EntityId, x.TagId});
b.HasIndex(x => new { x.TenantId, x.EntityId, x.TagId });
});
}
@ -203,7 +205,30 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.Property(x => x.Url).IsRequired().HasMaxLength(PageConsts.MaxUrlLength);
b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength);
b.HasIndex(x => new {x.TenantId, x.Url});
b.HasIndex(x => new { x.TenantId, x.Url });
});
}
if (GlobalFeatureManager.Instance.IsEnabled<BlogsFeature>())
{
builder.Entity<Blog>(b =>
{
b.ToTable(options.TablePrefix + "Blogs", options.Schema);
b.ConfigureByConvention();
b.Property(p => p.Name).IsRequired().HasMaxLength(BlogConsts.MaxNameLength);
});
builder.Entity<BlogPost>(b =>
{
b.ToTable(options.TablePrefix + "BlogPosts", options.Schema);
b.ConfigureByConvention();
b.Property(p => p.Title).IsRequired().HasMaxLength(BlogPostConsts.MaxTitleLength);
b.Property(p => p.CoverImageUrl).HasMaxLength(BlogPostConsts.MaxCoverImageUrlLength);
});
}
}

Loading…
Cancel
Save