Advertisement
LYSoft

Untitled

May 12th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. // Article
  2.     public class Article : LoganBaseObject<Article>
  3.     {
  4.         public string ArticleTitle { get; set; }
  5.         public virtual User Author { get; set; }
  6.         public string Content { get; set; }
  7.         public DateTime DatePosted { get; set; }
  8.         public Int32 Likes { get; set; }
  9.         public Int32 Dislikes { get; set; }
  10.  
  11.         public virtual ICollection<ArticleComment> Comments { get; set; }
  12.  
  13.         public Article()
  14.         {
  15.             ArticleTitle = String.Empty;
  16.             Content = String.Empty;
  17.             Likes = 0;
  18.             Dislikes = 0;
  19.  
  20.             Comments = new List<ArticleComment>();
  21.         }
  22.  
  23.     }
  24.  
  25. // ArticleDBContext
  26.     public class ArticleDBContext : LoganDBBaseObject<Article>
  27.     {
  28.         public ArticleDBContext()
  29.             : base()
  30.         {
  31.             Property(p => p.ArticleTitle)
  32.                 .HasColumnName("sTitle")
  33.                 .HasMaxLength(50)
  34.                 .IsRequired();
  35.  
  36.             Property(p => p.DatePosted)
  37.                 .HasColumnName("dCreateDate")
  38.                 .IsRequired();
  39.            
  40.             HasRequired(r => r.Author)
  41.                 .WithMany(m => m.Articles)
  42.                 .WillCascadeOnDelete(false);
  43.  
  44.             Property(p => p.Content)
  45.                 .HasColumnType("text")
  46.                 .IsRequired();
  47.  
  48.             HasMany(m => m.Comments);
  49.  
  50.         }
  51.     }
  52.  
  53. // LoganBaseObject
  54. // NOTE: Not sure what this is for... a friend helped me with it when he was introducing me to code-first
  55.  
  56.     public abstract class LoganBaseObject<T>
  57.         where T : LoganBaseObject<T>
  58.     {
  59.         public Int64 PKey { get; set; }
  60.  
  61.         public LoganBaseObject()
  62.         {
  63.             PKey = 0;
  64.         }
  65.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement