There are three types of relationships in database. They are: One-to-Many One-to-One Many-to-Many The One-to-Many relationship Write some codes first: class Company { public int CompanyId { get; set; } [MaxLength(50)] public string CompanyName { get;…
[索引页][源码下载] 精进不休 .NET 4.5 (12) - ADO.NET Entity Framework 6.0 新特性, WCF Data Services 5.6 新特性 作者:webabcd 介绍精进不休 .NET 4.5 ADO.NET Entity Framework 6.0 新特性 WCF Data Services 5.6 新特性 示例1.演示 ADO.NET Entity Framework 6.0 的新特性 - 对 async await 的支持EF6.aspx <%…
Sometimes, you need to find some data in an existing context instead of the database. By befault, Entity Framework always find data in database. If you want to find data which have loaded in memory, please do it like this: Frist of all, let's insert…
The default Way to handle concurrency of Entity Framework is using optimistic concurrency. When two clinets update the same entity, one of theirs data will be lost without any notify. Some times, the client want to know if his data has been saved suc…
Creating Entities First of all, Let's create some entities to have a test. Create a project Add following packages by NuGet EntityFramework MySql.Data.Entity (I'm just using MySql, it's not necessary) Add some codes: class Class { public int ClassId…
There are three ways to define the database structure by Entity Framework API. They are: Attributes The DbModelBuilder API Configuration Classes Attributes We can Add some attributes for entities or proteries to configure database structures. For exa…
Sometimes, you have created two models. They have the same parent class like this: public class Person { public int PersonId { get; set; } public string PersonName { get; set; } } public class InsidePerson : Person { public string Title { get; set; }…
Entity Framework Code First 利用一种被称为约定(Conventions)优于配置(Configuration)的编程模式允许你使用自己的 domain classes 来表示 EF 所依赖的模型去执行查询.更改追踪.以及更新功能,这意味着你的 domain classes 必须遵循 EF 所使用的约定.然而,如果你的 domain classes 不能遵循 EF 所使用的约定,此时你就需要有能力去增加一些配置使得你的 classes 能够满足 EF 所需要的信息. C…
Complex types are classes that map to a subset of columns of a table.They don't contains key. They are the Value Objects. For example, you have a entity named Company: public class Company { public int CompanyId { get; set; } public string CompanyNam…
Sometimes, We want to check the original sql statements. creating a commandInterceptor is a good way to do this. Add a class named MyCommandInterceptor class MyCommandInterceptor: DbCommandInterceptor { public override void NonQueryExecuted(DbCommand…
Create a new project named MySqlTest Install following packages by right-clicking on the References folder of the project and selecting Manage NuGet Packages... EntityFramework MySql.Data MySql.data.Entity Update the app.config file Add a model and t…
Joins allow developers to combine data from multiple tables into a sigle query. Let's have a look at codes: Creating a project Create a project named JoinTest Add Packages by NuGet Create entities: public class Person { public int PersonId { get; set…
Sometimes, you've created a table for example named Person. Just then, you want to add some extra information, but don't want to add any new field into the existed table Person. You just want to add a new table named PersonContact. Both two table hav…
好久没写博客了,继续开启霸屏模式,好了,废话不多说,这次准备重新系统学一下EF,一个偶然的机会找到了一个学习EF的网站(http://www.entityframeworktutorial.net/).准备按照上面一点一点学,学习之路,贵在坚持,贵在持之以恒,这是我给自己的忠告,我不聪明,但我愿意花比别人更多的时间,来学习,相信总有一天,总会有守得花开见月明的那一天! EF学习系列: 1.基本的EF系列教程 [Basics of Entity Framework][EF基础系列1] EF是啥?[…
本文主要的目的是 1. 说明Entity Framework Power Tools如何使用. 2. Entity Framework  快速门 实验环境: OS: Windows Server 2012, Windows 7 DE: VS2013 + MVC 6.0+Entity Framework+ SQL Server 2012 准备工作 基于现有数据库生成POCO数据类和数据库上下文需要借助Visual Studio一个扩展插件-- Entity Framework Power Tool…
第7章 高级概念 The Code First modeling functionality that you have seen so far should be enough to get you up and running with most applications. However, Code First also includes some more advanced functionality that you may require as your needs advance.…
策略一:数据库不存在时重新创建数据库 Database.SetInitializer<testContext>(new CreateDatabaseIfNotExists<testContext>()); 策略二:每次启动应用程序时创建数据库 Database.SetInitializer<testContext>(new DropCreateDatabaseAlways<testContext>()); 策略三:模型更改时重新创建数据库 Database.…
在前面的文章中我们提到Entity Framework的"Code First"模式也同样可以基于现有数据库进行开发.今天就让我们一起看一下使用Entity Framework Power Tools如何基于现有数据库生成数据类和数据库上下等. Entity Framework Power Tools 基于现有数据库生成POCO数据类和数据库上下文需要借助Visual Studio一个扩展插件-- Entity Framework Power Tools(一个Code First反向工…
Creating a complex data model 创建复杂数据模型 8 of 9 people found this helpful The Contoso University sample web application demonstrates how to create ASP.NET Core 1.0 MVC web applications using Entity Framework Core 1.0 and Visual Studio 2015. For informa…
原文地址:https://docs.asp.net/en/latest/data/ef-mvc/intro.html The Contoso University sample web application demonstrates how to create ASP.NET Core 1.0 MVC web applications using Entity Framework Core 1.0 and Visual Studio 2015. Contoso University网络应用的案…
http://www.entityframeworktutorial.net/Types-of-Entities.aspx We created EDM for existing database in the previous section. As you have learned in the previous section that EDM contains entities for each table in the database. There are two types of…
在本教程中使用的软件版本 Visual Studio 2013 年 4.5.NET 实体框架 (EntityFramework 6.1.0 NuGet 包) 6 Windows Azure SDK 2.2(可选) 安装EntityFramework 6 从工具菜单上单击库的软件包管理器,然后单击程序包管理器控制台. 在软件包管理器控制台窗口中输入下面的命令: Install-Package EntityFramework 该图像显示了 6.0.0 正在安装,但 NuGet 将安装最新的预发行版本…
Get Entity Framework: http://msdn.microsoft.com/en-us/data/ee712906 Entity Framework 6 Tools for Visual Studio 2012 & 2013: http://www.microsoft.com/en-us/download/details.aspx?id=40762…
在前面的文章中我们提到Entity Framework的“Code First”模式也同样可以基于现有数据库进行开发.今天就让我们一起看一下使用Entity Framework Power Tools如何基于现有数据库生成数据类和数据库上下等. Entity Framework Power Tools 基于现有数据库生成POCO数据类和数据库上下文需要借助Visual Studio一个扩展插件-- Entity Framework Power Tools(一个Code First反向工程工具).…
Entity Framework 学习初级篇1--EF基本概况 Entity Framework 学习初级篇2--ObjectContext.ObjectQuery.ObjectStateEntry.ObjectStateManager类的介绍 Entity Framework 学习初级篇3-- LINQ TOEntities Entity Framework 学习初级篇4--EntitySQL Entity Framework 学习初级篇5--ObjectQuery查询及方法 Entity F…
This article is dedicated to discussing the latest releases of the NHibernate and Entity Framework. NHibernate is (was?) a number one ORM Framework for ages. Its feature list is growing and some things such as code-based mappings and automatic migrat…
原文地址:http://www.cnblogs.com/kenshincui/archive/2013/08/29/3290527.html 在前面的文章中我们提到Entity Framework的“Code First”模式也同样可以基于现有数据库进行开发.今天就让我们一起看一下使用Entity Framework Power Tools如何基于现有数据库生成数据类和数据库上下等. Entity Framework Power Tools 基于现有数据库生成POCO数据类和数据库上下文需要借助…
转载自:https://ilmatte.wordpress.com/2013/01/06/entity-framework-joining-in-memory-data-with-dbset/ The argument of this post is relevant to people using Entity Framework and needing to filter data coming from a Database with a list of in-memory data. I…
问题 不管你用DBFirst,ModelFirst或是CodeFirst的方式,你想用实体键获取一个单独的实体.在本例中,我们用CodeFirst的方式. 解决方案 假设你有一个模型表示一个Painting(绘画)类型的实体,如Figure 13-2所示: Figure 13-2. The Painting entity type in our model 在代码In Listing 13-2,我们创建实体类Painting. public class Painting { public str…
DbContext.DbSet及DbQuery是Entity Framework Code First引入的3个新的类,其中DbContext用于保持数据库会话连接,实体变化跟踪及保存,DbSet用于暂存实体类的变化跟踪,DbQuery用于提供查询跟你. 1.使用Set查询全部记录 使用DbContext查询首先需要保证DbContext的实例在使用完之后对资源的释放,释放DbContext实例资源的方法有两种:采用using代码块结构和调用DbContext实例的Dispose()方法. us…