`
mnhkahn
  • 浏览: 29021 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

使用Entity Framework创建Model

    博客分类:
  • .NET
阅读更多

在ASP.NET MVC中,可以使用Entity Framework创建Model。

在创建好的Model中,一个为.edmx文件,实质为XML文件,主要保存了Model的实体设计图;另一个为.Designer.cs文件,用类封装了的数据库对象。

在.Designer.cs文件中,有一个Enitities类,继承自ObjectContext,是用来表示整个Model的类。它还为数据库中每个表创建了一个用实际表名称命名的public的属性,可以直接对表进行操作。在对数据库进行操作时,首先要new一个Entities对象,然后就可以进行AddTo、DeleteObject、SaveChanges,或者调用前面说的public属性来对表进行修改操作。

在.Designer.cs文件中,还有为每个数据库表创建的对象,有多少个表就有多少个这样的对象,它们的名称和表的名称相同。可以用来存放数据。

以Model名称为sseModel、表名称为News为例,在进行Add操作时,代码如下:

 

private sseEntities _db;
public NewsController()
{
        _db = new sseEntities();
}
public void AddNews(FormCollection form)
{
         News news = News.CreateNews(1, DateTime.Now, "Zidane", "123",
         "Zidane", "Fuck", true, true);
         _db.AddToNews(news);
         _db.SaveChanges();
}

 

参考:http://www.cnblogs.com/haoliansheng/archive/2010/04/27/1722342.html

 

0
0
分享到:
评论

相关推荐

    Mastering Entity Framework(PACKT,2015)

    Entity Framework provides a model-based system that makes data access effortless for developers by freeing you from writing similar data access code for all of your domain models. Mastering Entity ...

    Entity Framework 教程

    Entity Framework的核心 – EDM(Entity Data Model) 7 EDM概述 7 EDM之CSDL 7 EDM之SSDL 11 EDM之MSL 12 EDM中存储过程的设计 15 EDM中ComplexType的设计 16 实体数据模型映射方案 17 Entity Framework的...

    Entity Framework 6 Recipes,最新资料

    Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsoft's model-centric, data-access platform for the .NET Framework and ASP.NET ...

    EntityFramework6.1.3源码

    ADO.NET Entity Framework 以 Entity Data Model (EDM) 为主,将数据逻辑层切分为三块,分别为 Conceptual Schema, Mapping Schema 与 Storage Schema 三层,其上还有 Entity Client,Object Context 以及 LINQ 可以...

    Pro Entity Framework Core 2 for ASP.NET Core MVC

    Model, map, and access data effectively with Entity Framework Core 2, the latest evolution of Microsoft’s object-relational mapping framework that allows developers to access data using .NET objects,...

    Entity.Framework.Tutorial.2nd.Edition.1783550015

    A comprehensive guide to the Entity Framework with insight into its latest features and optimizations for responsive data access in your projects About This Book Create Entity data models from your ...

    ASP.NET MVC with Entity Framework and CSS

    ASP.NET MVC with Entity Framework and CSS by Lee Naylor 2016 | ISBN: 1484221362 | English | 608 pages | True PDF | 30 MB This book will teach readers how to build and deploy a fully working example ...

    简单的EntityFramework4.3+三层+DTO 简单Demo

    简单的EntityFramework4.3+三层+DTO,如果需要简化版的,我的资源里有一个不含DTO的版本。 这个Demo的主要功能是: 1、实体类的创建、复杂类型的嵌套 2、实体类的配置(主键、外键、一对一、1对多,多对多) 3、...

    Entity Framework 6 Power Tools Community Edition

    View Entity Data Model (Read-only) View Entity Data Model XML View Entity Data Model DDL SQL Generate Views When right-clicking on an Entity Data Model .edmx file, the following context menu ...

    Pro Entity Framework 4.0

    Chapter 1: Introducing the ADO.NET 4.0 Entity Framework..................................1 Chapter 2: The Entity Data Model ........................................................13 Chapter 3: The ...

    Programming Entity Framework: Building Data Centric

    Written by JuliaLerman, the leading independent authority on the framework,Programming Entity Framework covers it all -- from the Entity DataModel and Object Services to WCF Services, MVC Apps, and ...

    Programming Entity Framework: Code First

    Model that is core to Entity Framework Rather than using a visual designer Code First allows you to create the model from your existing classes This book is dedicated to teaching readers how to use ...

    Entity Framework Core in Action-原版

    You'l start with a clear breakdown of Entity Framework, long with the mental model behind ORM. Then you'll discover time-saving patterns and best practices for security, performance tuning, and even ...

    Programming Entity Framework Code First

    Model that is core to Entity Framework. Rather than using a visual designer, Code First allows you to create the model from your existing classes. This book is dedicated to teaching readers how to use...

    EntityFramework入门教程实例

    ADO.NET Entity Framework 以 Entity Data Model (EDM) 为主,将数据逻辑层切分为三块,分别为 Conceptual Schema, Mapping Schema 与 Storage Schema 三层,其上还有 Entity Client,Object Context 以及 LINQ 可以...

    Entity Framework 6 Recipes 第二版(英文高清pdf)

    Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsofts model-centric, data-access platform for the .NET Framework and ASP.NET ...

    Pro Entity Framework Core 2 for ASP.NET Core MVC--2018

    Gain a solid architectural understanding of Entity Framework Core 2 Learn how to create databases using your MVC data model Learn how to create MVC models using an existing database Learn how to ...

    Programming Entity Framework, 2nd Edition

    Written by Julia Lerman, the leading independent authority on the framework, Programming Entity Framework covers it all - from the Entity Data Model and Object Services to WCF Services, MVC Apps, and...

    [EF] Entity Framework 6 开发技巧 (英文版)

    Entity Framework 6 Recipes provides an exhaustive collection of ready-to-use code solutions for Entity Framework, Microsoft's model-centric, data-access platform for the .NET Framework and ASP.NET ...

Global site tag (gtag.js) - Google Analytics