冯 海

一个程序新人菜鸟的日记,希望大家多多关照。QQ:32316131

bootstrap adminlte教程4-1:文章CMS,社区问答,栏目管理(1建模)

1.先建一个栏目管理。按TPYE分类,1等于CMS,2等问答

在Models下新建CmsColumn.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace jsdhh2.Models
{
	public class CmsColumn
	{
		/// <summary>
		/// 菜单ID
		/// </summary>
		[Display(Name = "栏目id")]
		public int Id { get; set; }
		/// <summary>
		/// 名称
		/// </summary>
		[Display(Name = "栏目名称")]
		 
		[Required(ErrorMessage = "名称是必须的!")]
		public string Name { get; set; }

		[Display(Name = "排序数字")]
		public int  Order { get; set; }


		[Display(Name = "类型")]

		public string ColumnType { get; set; }

		[Display(Name = "阅读者")] 
		public string UserList { get; set; }






	}


}

  2.建模型ClubContent

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace jsdhh2.Models
{
	public class ClubContent
	{
		/// <summary>
		/// 菜单ID
		/// </summary>
		[Display(Name = "文章id")]
		public string Id { get; set; }

		[Display(Name = "创建日期 Date")]
		[DataType(DataType.Date)]
		[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd  HH:mm:ss}")]

		public DateTime CreatTime { get; set; }

		[Display(Name = "修改日期 Date")]
		[DataType(DataType.Date)]
		[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd  HH:mm:ss}")]

		public DateTime EditTime { get; set; }

		public int ColumnId { get; set; }
		[StringLength(60, MinimumLength = 3, ErrorMessage = "主题的长度必须在3到60个字符")]
		public string Title { get; set; }
	    [Required]
		public string Contents { get; set; }

		public string CreatUser { get; set; }
		public string ReplyID { get; set; }

		public string PcIp { get; set; }
		public int ReplyCount { get; set; }
		public string ClubPermission { get; set; }

		public string ClubState { get; set; }


		public int ClubOerder{ get; set; }











	}
}

  3.建模型CmsContent

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace jsdhh2.Models
{
	public class CmsContent
	{
		/// <summary>
		/// 菜单ID
		/// </summary>
		[Display(Name = "文章id")]
		public string Id { get; set; }

		 [Display(Name = "创建日期 Date")]
          [DataType(DataType.Date)]
         [DisplayFormat(DataFormatString = "{0:yyyy-MM-dd  HH:mm:ss}")]

		public DateTime CreatTime { get; set; }
		public int ColumnId { get; set; }

		[StringLength(60, MinimumLength = 3, ErrorMessage = "主题的长度必须在3到60个字符")]
         public string Title { get; set; }

		[Required]
		public string Contents { get; set; }
		public string CreatUser { get; set; }
		
		public string ReplyID { get; set; }

		public string PcIp { get; set; }
		public int ReplyCount { get; set; }

		public string CmsPermission { get; set; }

		public string UserList { get; set; }
		public string yulou1 { get; set; }
	}
}

  

4.更改上下文。在DAL下的OaDALContent.cs

using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using jsdhh2.Models;

namespace jsdhh2.DAL
{
	public class OaDALContent : DbContext
	{
		public OaDALContent() : base("MyOaContent") { }
		public DbSet<Menu> Menus { get; set; }

		public DbSet<MenuRole> MenuRoles { get; set; }

		public DbSet<CmsColumn> CmsColumns { get; set; }
		public DbSet<ClubContent> ClubContents { get; set; }
		public DbSet<CmsContent> CmsContents { get; set; }
	}


}

  

5.新建三个控制器,都使用EF的视图的。选中三个新建的MOEL,OaDALContent 为连接字符串

 

 

6.然后重新生成方案。

点击调测。

登录后,改为http://localhost:55850/CmsContents回车的错误

 

在VS2017中使用控制台:

先删除二个first配置文件

然后在控制台使用:

Enable-Migrations 

  

 

复制:

Enable-Migrations -ContextTypeName jsdhh2.DAL.OaDALContent

  

然后再进入这个新增的配置文件瘵false改为True

然后再输入

PM>  update-database 

  

然后刷新数据库,会发现所有表已新建完成。

 

 

posted @ 2017-05-30 00:06  秋天来了哟  阅读(329)  评论(0编辑  收藏  举报
认识就是缘份,愿天下人都快乐!
QQ: 32316131
Email: 32316131@qq.com