MVC5 + EF6 简单示例(转载)

原文地址:http://www.cnblogs.com/panchunting/p/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application.html

MVC4+EF5+EasyUI+Unity3依赖注入(1)- 系统简要说明

http://www.cnblogs.com/hbsi/p/3632015.html

ASP.NET MVC5 网站开发实践

http://www.cnblogs.com/mzwhj/archive/2014/03/30/3634397.html

 EF5&MVC4 学习1、创建新的Contoso University Application,并创建Model Class 生成对应的database

http://www.cnblogs.com/siri/p/3628017.html

http://www.cnblogs.com/siri/category/558088.html

Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)

http://www.asp.net/mvc/tutorials/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

最终效果如下图

 

模型类和数据上下文都是下拉菜单选择的。注意:在选择之前先编译一下你的代码,否则是找不到模型类和数据上下文类的

服务器资源管理器:

另外关于:

using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using EF6Demo.Models;

namespace EF6Demo.DAL
{
    public class CommunicationContext:DbContext
    {
        public CommunicationContext()
            : base("CommunicationContext")
        { 
            
        }
        public DbSet<EF6Demo.Models.Contact> Contacts { get; set; }
        public DbSet<EF6Demo.Models.Enrollment> Enrollments { get; set; }
        public DbSet<EF6Demo.Models.Group> Groups { get; set; }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //base.OnModelCreating(modelBuilder);
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        }
    }
}

 

 modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();可以参考:

Entity Framework creates a plural table name, but the view expects a singular table name?

http://stackoverflow.com/questions/7924758/entity-framework-creates-a-plural-table-name-but-the-view-expects-a-singular-ta

posted @ 2014-03-30 22:03  高山-景行  阅读(857)  评论(0编辑  收藏  举报