• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

简易留言薄系统-ASP.NET MVC(Model层)

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

我的开发顺序是从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; }
}
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap