Skip to content

Instantly share code, notes, and snippets.

@codebeaulieu
Created May 19, 2015 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codebeaulieu/3ec0f8a5a36e4e5cacd0 to your computer and use it in GitHub Desktop.
Save codebeaulieu/3ec0f8a5a36e4e5cacd0 to your computer and use it in GitHub Desktop.
Post.cs | Stack Overflow | How do I use OnModelCreating with ApplicationDbContext?
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;
namespace BlogEngine.Models
{
public class Post : IEntity
{
[Key]
public int Id { get; set; }
[Required]
//[StringLength(50, MinimumLength = 5, ErrorMessage = "Title must be between 5 and 50 characters long")]
public string Title { get; set; }
public string URL { get; set; }
[Required]
//[StringLength(250, MinimumLength = 50, ErrorMessage = "IntroText must be between 50 and 250 characters long")]
public string IntroText { get; set; }
[Required]
//[StringLength(9999, MinimumLength = 50, ErrorMessage = "Enter something long enough to be worth clicking on please.")]
public string Body { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[Column(TypeName = "DateTime")]
public DateTime Created { get; set; }
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
[Column(TypeName = "DateTime")]
public DateTime? Modified { get; set; }
[Required]
//[StringLength(50, MinimumLength = 5, ErrorMessage = "Author's name must be between 5 and 50 characters long")]
public string Author { get; set; }
public List<Comment> Comments { get; set; }
public int? Tags_Id { get; set; }
[ForeignKey("Tags_Id")]
public virtual List<Tag> Tags { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment