我的开发顺序是从Model层开始。在Model层目前一共有4个类。Model层除MvcBbsContext引用了System.componentModel 与 System.ComponentModel.DataAnnotations,在MvcBbsContext类中引用了System.Data.Entity
1.User
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
namespace MvcBBSApplication.Models
{
public class User
{
[Key]
public int Id { get; set; }
[DisplayName("UserName")]
[Required(ErrorMessage = "Please enter the Email")]
[DataType(DataType.EmailAddress, ErrorMessage = "Please enter the correct format")]
public string Email { get; set; }
[DisplayName("NickName")]
[Required(ErrorMessage = "Please enter the NickName")]
[MaxLength(10, ErrorMessage = "MaxLength 20 words")]
public string NickName { get; set; }
[DisplayName("Password")]
[Required(ErrorMessage = "Please enter the Password")]
[MaxLength(10, ErrorMessage = "MaxLength 10 words")]
[DataType(DataType.Password)]
public string Password { get; set; }
[DisplayName("CreatOn")]
[Required]
public DateTime CreatOn { get; set; }
}
}
-------------------------------------------------------------
2.Message
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace MvcBBSApplication.Models
{
public class Message
{
[Key]
public int Id { get; set; }
[DisplayName("Title")]
[Required(ErrorMessage = "Please enter the Title")]
[MaxLength(50, ErrorMessage = "MaxLength 50 words")]
public string Title { get; set; }
[DisplayName("UserName")]
public User User { get; set; }
[DisplayName("Content")]
[DataType(DataType.MultilineText)]
public string content { get; set; }
[DisplayName("CreatOn")]
[Required]
public DateTime CreatOn { get; set; }
[DisplayName("IpAddress")]
[Required]
public string Ip { get; set; }
}
}
----------------------------------------------
3.Reply
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace MvcBBSApplication.Models
{
public class Reply
{
[Key]
public int Id { get; set; }
[DisplayName("Title")]
public Message Message { get; set; }
[DisplayName("UserName")]
public User User { get; set; }
[DisplayName("Content")]
[Required(ErrorMessage="Please enter content")]
[DataType(DataType.MultilineText)]
public string Content { get; set; }
[DisplayName("CreatOn")]
[Required]
public DateTime CreatOn { get; set; }
[DisplayName("IpAddress")]
[Required]
public string Ip { get; set; }
}
}
------------------------------------------------
4.MvcBbsContext
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MvcBBSApplication.Models
{
public class MvcBbsContext:DbContext
{
public MvcBbsContext()
: base("name=DefaultConnection")
{
}
public DbSet<User> Users { get; set; }
public DbSet<Message> Messages { get; set; }
public DbSet<Reply> Replys { get; set; }
}
}
请发表评论