上一篇 第二篇:Entity Framework CodeFirst & Model 映射 主要介绍以Fluent API来实作EntityFramework CodeFirst,得到了大家一些支持,其中就有一位同学就提出.熟悉了EntityFramework CodeFirst 原理,就可以用微软的工具来生产代码.是的,今天就来讲一下,由微软EntityFramework小组开发的为EntityFramework CodeFirst Visual Studio小插件 “Entity Frame…
前一篇 第一篇:Entity Framework 简介 我有讲到,ORM 最关键的 Mapping,也提到了最早实现Mapping的技术,就是 特性 + 反射,那Entity Framework 实现Mapping 又是怎样的呢? EntityFramework 实现Mapping 有两种方式. 1. 数据注解(DataAnnotations) 2. Fluent API 一. 数据注解,这种方式,就是在实体和属性加上一些EntityFramework 定义好的一些特性,然后EntityFram…
离上一篇博客,快一周,工作太忙,只能利用休息日来写一些跟大家分享,Entity Framework Plus 组件系列文章,之前已经写过两篇 第一篇 Entity Framework Plus 之 Audit 第二篇 Entity Framework Plus 之 Query Future 计划还会写两篇,一篇是关于查询缓存的(二级缓存),一篇是批量操作(只讲更新,删除). 今天写查询缓存,标题 第三篇 Entity Framework Plus 之 Query Cache  ,废话不多说,直接…
警告:这是一个入门级日志,如果你很了解CodeFirst,那请绕道 背景:这篇日志记录我使用Entity FrameWork CodeFirst时出现的错误和解决问题的过程,虽然有点曲折……勿喷 备注:这确实算是Entity FrameWork CodeFirst的问题个人也不知道应该给文章加什么样的关键字和标题,方便各位朋友搜索 一.问题出现 当我参考 洞庭夕照 博客 ASP.NET MVC5 网站开发实践 - 概述 按照代码一点点尝试CodeFirst(虽然这不是一个针对CodeFirst的…
前言 紧接着前面一篇博文Entity Framework CodeFirst尝试. 我们知道无论是“Database First”还是“Model First”当模型发生改变了都可以通过Visual Studio设计视图进行更新,那么对于Code First如何更新已有的模型呢?今天我们简单介绍一下Entity Framework的数据迁移功能. Entity Framework配置 当我们对项目进行Entity Framework进行安装引用的时候,同时生成了两个配置文件 packages.c…
从性能的角度出发,能够减少 增,删,改,查,跟数据库打交道次数,肯定是对性能会有所提升的(这里单纯是数据库部分). 今天主要怎样减少Entity Framework查询跟数据库打交道的次数,来提高查询性能. 举一个大家最常用功能 “分页” 功能.先贴一段代码. private static IEnumerable<OrderModel> FindPagerOrders(int pageSize, int pageIndex, out int totalCount) { using (var d…
Migration in Code-First: Entity framework Code-First had different database initialization strategies prior to EF 4.3 like CreateDatabaseIfNotExists, DropCreateDatabaseIfModelChanges, or DropCreateDatabaseAlways. However, there were some problems wit…
After you have introduced a data model, you may need to have the application populate the database with a predefined set of objects. In this topic, you will learn how to add data to the database in code when the application runs. For this purpose, th…
ADO.NET Entity Framework CodeFirst 如何输出日志(EF4.3) 用的EFProviderWrappers ,这个组件好久没有更新了,对于SQL执行日志的解决方案的需求是杠杠的,今天给大家介绍一个更好的组件Clutch.Diagnostics.EntityFramework,可以通过Nuget 获取: 这个框架定义了一个接口 IDbTracingListener: namespace Clutch.Diagnostics.EntityFramework { pub…
1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the '' context has changed since the database was create 解决方法: 1.打开当前项目中的:程序包管理器控制台 2.输入:enable-migrations -ProjectName 'ProductModel' -Force 解释:'ProductModel',e…
本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)   By    …
Cascade Delete in Entity Framework Code-First: Cascade delete automatically deletes dependent records or set null to foreignkey properties when the principal record is deleted. Cascade delete is enabled by default in Entity Framework for all types of…
Setup Development Environment for EF Code-First: Let's setup the development environment for Code-First before starting on it. Install the following tools to work with Entity Framework Code-First: .NET Framework 4.5 Visual Studio 2012 MS SQL Server 2…
Entity Framework Code-First: Learn Entity Framework Code-First in simple step-by-step tutorials. These tutorials cover all the features of Entity Framework Code-First starting with the basics of code-first, DB migration, configuring one-to-one, one-t…
If you have a non-XAF application, and want to develop an XAF application that utilizes the same database, you can generate business classes for an existing database to achieve this task. However, if your existing application is based on the Entity F…
Entity Framework Codefirst的配置步骤: (1) 安装命令: install-package entityframework (2) 创建实体类,注意virtual关键字在导航属性中的用法 (3) 创建DbContext类,为每个entity set创建一个DbSet:    指定一个连接字符串构造函数中的 base("AccountContext") .    设置表的单数形式 public class AccountContext:DbContext { p…
一般系统会有登陆日志,操作日志,异常日志,已经满足大部分的需求了.但是有时候,还是需要Audit 审计日志,审计日志,主要针对数据增,改,删操作数据变化的记录,主要是对数据变化的一个追踪过程.其中主要追踪数据关键点如下 1. 新增 具体新增哪些数据,值是什么,新增人谁. 2. 修改 具体修改哪些数据,之前值是什么,修改后值是什么,修改人谁. 3. 删除 具体删除哪些数据,之前值是什么,删除人谁. 有了这个Audit追踪过程,当那天,用户操作的数据出现问题,你就可以根据这个Audit将数据恢复到某…
以下是书<Programming Entity Framework Code First>的学习整理,主要是一个整体梳理. 一.模型属性映射约定 1.通过 System.Component  Model.DataAnnotations 来配置 class AnimalType { public int Id { get; set; } [Required] public string TypeName { get; set; } } 意味着TypeName在数据库中的字段为not null.第…
在实现基础的三层开发的时候,大家时常会在数据层对每个实体进行CRUD的操作,其中存在相当多的重复代码.为了减少重复代码的出现,通常都会定义一个共用类,实现相似的操作,下面为大家介绍一下Entity Framework时常用到的通用类.首先在数据库建立起几个关联表:Person.Company.Position,三个实体之间通过导航属性进行相互引用. 下面为大家分别介绍以泛型实现的 Create.Read.Update.Delete 操作: 1. Create 在ObjectContext类之中,…
用 Entity Framework  进行 增,删,改.都是基于Model进行的,且Model都是有状态追踪的.这样Entity Framework才能正常增,删,改. 有时候,要根据某个字段,批量更新或者删除数据,用Entity Framework就会显得很是繁琐,且不高效. Entity Framework Plus 为Entity Framework 提供 BatchUpdate 和 BatchDelete 操作扩展.使得更新和删除数据,变得简单而高效了许多. 废话不多说,直接实践给大家…
前言 Code First模式我们称之为“代码优先”模式,是从EF4.1开始新建加入的功能.使用Code First模式进行EF开发时开发人员只需要编写对应的数据类(其实就是领域模型的实现过程),然后自动生成数据库.这样设计的好处在于我们可以针对概念模型进行所有数据操作而不必关系数据的存储关系,使我们可以更加自然的采用面向对象的方式进行面向数据的应用程序开发. 从某种角度来看,其实“Code First”和“Model First”区别并不是太明显,只是它不借助于实体数据模型设计器,而是直接通过…
转载 http://www.th7.cn/Program/net/201301/122153.shtml Code First如何处理类之间的继承关系.Entity Framework Code First有三种处理类之间继承关系的方法,我们将逐一介绍这三种处理方法. 1.Table Per Hierarchy(TPH): 只建立一个表,把基类和子类中的所有属性都映射为表中的列. 2.Table Per Type(TPT): 为基类和每个子类建立一个表,每个与子类对应的表中只包含子类特有的属性对…
Entity Framework Power Tools: Entity Framework Power Tools (currently in beta 3) has been released. EF Power Tools is useful mainly in reverse engineering and generating read-only entity data model for code-first. Download and install Power Tools fro…
Automated Migration: Entity framework 4.3 has introduced Automated Migration so that you don't have to process database migration manually in the code file, for each change you make in your domain classes. You just need to run a command in Package Ma…
Code-First from an Existing Database: Here, you will learn how to generate code-first context and entity classes for an existing database. Entity Framework provides an easy way to use code-first approach for an existing database. It will create entit…
Inheritance Strategy in Code-First: We have seen in the Code First Conventions section that it creates database tables for each concrete domain class. However, You can design your domain classes using inheritance. Object-oriented techniques include "…
Code First Conventions: We have seen how EF Code-First creates DB tables from domain classes in the previous section. Here, we will learn about default Code-First conventions. What is Convention? Convention is a set of default rules to automatically…
Simple Code First Example: Let's assume that we want to create a simple application for XYZ School. Users of this School application should be able to add or update Students, Standard (Grade), Teacher, and Course information. Instead of designing dat…
TOPIC about_EntityFramework SHORT DESCRIPTION Provides information about Entity Framework commands. LONG DESCRIPTION This topic describes the Entity Framework commands. Entity Framework is Microsoft's recommended data access technology for new applic…
Entity Framework Code First属性映射约定中“约定”一词,在原文版中为“Convention”,翻译成约定或许有些不好理解,这也是网上比较大多数的翻译,我们就当这是Entity Framework的一些使用“规则”,这样或许更好理解一些. Entity Framework Code First与数据表之间的映射方式有两种实现:Data Annotation和Fluent API.本文中采用创建Product类为例来说明tity Framework Code First属性…