EntityFramework 学习 一 Lazy Loading 1
延迟加载:延迟加载相关的数据
using (var ctx = new SchoolDBEntities())
{
//Loading students only
IList<Student> studList = ctx.Students.ToList<Student>(); Student std = studList[]; //Loads Student address for particular Student only (seperate SQL query)
StudentAddress add = std.StudentAddress;
}
首先查询Student表
SELECT
[Extent1].[StudentID] AS [StudentID],
[Extent1].[StudentName] AS [StudentName],
[Extent1].[StandardId] AS [StandardId]
FROM [dbo].[Student] AS [Extent1]
再查询StudentAddress表
exec sp_executesql N'SELECT
[Extent1].[StudentID] AS [StudentID],
[Extent1].[Address1] AS [Address1],
[Extent1].[Address2] AS [Address2],
[Extent1].[City] AS [City],
[Extent1].[State] AS [State]
FROM [dbo].[StudentAddress] AS [Extent1]
WHERE [Extent1].[StudentID] = @EntityKeyValue1',N'@EntityKeyValue1 int',@EntityKeyValue1=1
可以为指定的属性或整个上下文关闭延迟加载的功能,关闭属性的延迟加载功能就是不要设置属性为virtual
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using System.Linq; public partial class SchoolDBEntities : DbContext
{
public SchoolDBEntities(): base("name=SchoolDBEntities")
{
this.Configuration.LazyLoadingEnabled = false;
} protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
}
延迟加载的规则:
1.context.Configuration.ProxyCreationEnabled必须为true
2.context.Configuration.LazyLoadingEnabled必须为true
3.导航属性必须定义为public virtual
EntityFramework 学习 一 Lazy Loading 1的更多相关文章
- EntityFramework 学习 一   Lazy Loading
		延迟加载:延迟加载相关的数据 using (var ctx = new SchoolDBEntities()) { //Loading students only IList<Student&g ... 
- EntityFramework 学习 一   Explicit Loading with DBContext
		即使延迟加载不能使用,也可以通过明确的调用来延迟加载相关实体 使用DBEntryEntity来完成 using (var context = new SchoolDBEntities()) { //D ... 
- EntityFramework 学习 一   Eager Loading
		贪婪加载是指查询一个类型实体的时候同时查询与实体关联的类型 通过Include()方法实现 using (var context = new SchoolDBEntities()) { var stu ... 
- 你所不知道的库存超限做法  服务器一般达到多少qps比较好[转]  JAVA格物致知基础篇:你所不知道的返回码  深入了解EntityFramework Core 2.1延迟加载(Lazy Loading)   EntityFramework 6.x和EntityFramework Core关系映射中导航属性必须是public?  藏在正则表达式里的陷阱  两道面试题,带你解析Java类加载机制
		你所不知道的库存超限做法 在互联网企业中,限购的做法,多种多样,有的别出心裁,有的因循守旧,但是种种做法皆想达到的目的,无外乎几种,商品卖的完,系统抗的住,库存不超限.虽然短短数语,却有着说不完,道不 ... 
- Lazy Loading | Explicit Loading | Eager Loading in EntityFramework and EntityFramework.Core
		EntityFramework Eagerly Loading Eager loading is the process whereby a query for one type of entity ... 
- Angular2+typescript+webpack2(支持aot, tree shaking, lazy loading)
		概述 Angular2官方推荐的应该是使用systemjs加载, 但是当我使用到它的tree shaking的时候,发现如果使用systemjs+rollup,只能打包成一个文件,然后lazy loa ... 
- Lazyr.js – 延迟加载图片(Lazy Loading)
		Lazyr.js 是一个小的.快速的.现代的.相互间无依赖的图片延迟加载库.通过延迟加载图片,让图片出现在(或接近))视窗才加载来提高页面打开速度.这个库通过保持最少选项并最大化速度. 在线演示 ... 
- Can you explain Lazy Loading?
		Introduction Lazy loading is a concept where we delay the loading of the object until the point wher ... 
- [AngularJS] Lazy Loading modules with ui-router and ocLazyLoad
		We've looked at lazy loading with ocLazyLoad previously, but what if we are using ui-router and want ... 
随机推荐
- linux系统下面ftp的一些命令
			service vsftpd restart重启vsftpd服务service vsftpd stop停止vsftpd服务service vsftpd start启动vsftpd服务 chkconfi ... 
- Nginx服务启动脚本
			#!/bin/sh # chkconfig: 2345 40 98 # description: Start/Stop Nginx server path=/application/nginx/sbi ... 
- Linux基础之常用基本命令备忘
			Linux基础之常用基本命令备忘 PWD 查询当前所在Linux上的位置 / 根目录 CD(change directory)切换目录 语法 CD /(注意添加空格) LS ... 
- html中keydown事件
			实现在输入框按回车按钮进行查询的功能: 1.<input type="text" id="inputChannel" onkeydown="ke ... 
- apache重定向无效
			这个问题让我纠结了蛮久啊,因为之前一直不注意SEO,网站带www和不带www的一级域名都被收录了,而且不知道为什么不带www的一级域名被收录比www还多,这可不是我的初衷!这次吸取教训了,以后再开站不 ... 
- winerror.h中的内容(可以查看last error对应)
			/************************************************************************* ** winerror.h -- error co ... 
- 阿里巴巴产品实习生N天
			时间貌似有些太遥远,已经没办法从刚来时的日子一天一天数.连上内网打开内外.看到45天,每一次不经意的邂逅总会让人认为奇妙而微妙,每一次的巧合总会让人认为是神在显灵(但愿天津安好,这里也曾在我心中滋润过 ... 
- iOS开发 Xcode8 问题
			一.证书管理 用Xcode8打开工程后,比较明显的就是下图了,这个是苹果的新特性,可以帮助我们自动管理证书.建议大家勾选这个Automatically manage signing(Ps.但是在b ... 
- 第8章 Foundation Kit介绍
			本文转载至 http://blog.csdn.net/mouyong/article/details/16947321 Objective-C是一门非常精巧实用的语言,目前我们还没有研究完它提供的全 ... 
- task19-21
			[说明]理想是丰满的,现实很骨感,昨天还说今天有望干掉5个小任务,看来是没可能了,兜兜转转地做了一天也才完成下面的这些 一:今日完成 19.学习Spring,配置Spring和Junit 1)先安装一 ... 
