Skip to content

Instantly share code, notes, and snippets.

@mikecole
Created October 6, 2013 23:58
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 mikecole/6860676 to your computer and use it in GitHub Desktop.
Save mikecole/6860676 to your computer and use it in GitHub Desktop.
Customization with Data Annotations
[Table("Author")]
public class Author : EntityBase
{
public Author()
{
Posts = new Collection<Post>();
}
[Required]
[StringLength(50)]
public string Name { get; set; }
[StringLength(50)]
public string TwitterHandle { get; set; }
public virtual ICollection<Post> Posts { get; set; }
public int JobTitleID { get; set; }
[ForeignKey("JobTitleID")]
public virtual JobTitle JobTitle { get; set; }
}
[Table("Category")]
public class Category : EntityBase
{
public Category()
{
Posts = new Collection<Post>();
}
[Required]
[StringLength(50)]
public string Name { get; set; }
public virtual ICollection<Post> Posts { get; set; }
}
[Table("JobTitle")]
public class JobTitle : EntityBase
{
public JobTitle()
{
Authors = new Collection<Author>();
}
[Required]
[StringLength(50)]
public string Title { get; set; }
public virtual ICollection<Author> Authors { get; set; }
}
[Table("Post")]
public class Post : EntityBase
{
[Required]
[StringLength(150)]
public string Title { get; set; }
public string Url { get; set; }
public int AuthorID { get; set; }
[ForeignKey("AuthorID")] //For real? Bleh...
public virtual Author Author { get; set; }
public int PostCategoryID { get; set; }
[ForeignKey("PostCategoryID")]
public virtual Category Category { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment