Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Linq;
- using ConsoleBlog.Models;
- namespace ConsoleBlog.DataAccess
- {
- public class BlogContext : DbContext
- {
- //call base class with connection string name
- public BlogContext()
- : base("ForumDb")
- {
- }
- //Fluent API
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- // class with configuratios for Tag table
- modelBuilder.Configurations.Add(new TagMappings());
- modelBuilder.Entity<Post>().Property(x => x.Content).IsFixedLength().HasMaxLength(255);
- base.OnModelCreating(modelBuilder);
- }
- public DbSet<Category> Categories { get; set; }
- public DbSet<Post> Posts { get; set; }
- public DbSet<PostAnswer> PostAnswers { get; set; }
- public DbSet<Tag> Tags { get; set; }
- }
- }
- namespace CodeFirst.DataAccess
- {
- using System.Data.Entity.ModelConfiguration;
- using CodeFirst.Models;
- public class TagMappings : EntityTypeConfiguration<Tag>
- {
- public TagMappings()
- {
- this.HasKey(x => x.TagId);
- this.Property(x => x.Text).IsUnicode(true);
- this.Property(x => x.Text).HasMaxLength(255);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment