惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
C
CERT Recently Published Vulnerability Notes
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed
D
Darknet – Hacking Tools, Hacker News & Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
GbyAI
GbyAI
T
Tenable Blog
博客园 - 三生石上(FineUI控件)
P
Privacy & Cybersecurity Law Blog
Simon Willison's Weblog
Simon Willison's Weblog
Jina AI
Jina AI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
博客园_首页
F
Fortinet All Blogs
博客园 - Franky
Latest news
Latest news
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
U
Unit 42
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Hugging Face - Blog
Hugging Face - Blog
D
Docker
Project Zero
Project Zero
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
MongoDB | Blog
MongoDB | Blog
F
Full Disclosure
D
DataBreaches.Net
Google DeepMind News
Google DeepMind News
Cisco Talos Blog
Cisco Talos Blog
Y
Y Combinator Blog
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
H
Help Net Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Blog — PlanetScale
Blog — PlanetScale
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
Schneier on Security
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
V
Visual Studio Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理

博客园 - 无名

sql2005分页SQL 数据库设计原则 sql2005排名函数 如何提高数据库性能,减少数据库服务器压力瓶颈一两个小方法 sql Server 索引优化 看nettiers整理出来的codesmith模板编写要点 - 无名 - 博客园 .Net WinForm学习笔记 在javascript中,怎样响应键盘事件(转 - 无名 - 博客园 各分数段人数统计 排名问题 DataGrid - 导出Excel文件 DataGrid导出excel和word的例子 DataGrid - 导出Excel文件 利用剪切板将DataSet的数据导出到Excel DataGrid相关知识总结(收集自各位老大处) 使用DES加密解密代码(C# & vb.Net),好东东,拷得,贴一下 dataGrid的手写样式 在DNN中获取所有模块信息 几个DNN里的技巧(转)(真的是好东东啊)
Using DeepLoad In NetTiers
无名 · 2006-08-04 · via 博客园 - 无名

Using DeepLoad

The DeepLoad and DeepSave methods in NetTiers retrieve and make changes to all of the object’s associated with an instantiated object.   For example, the Employees object from Northwind includes an OrdersCollection, EmployeeTerritoriesCollection, and a TerritoriesCollection_From_EmployeeTerritories generated from a Many-Many relationship. The DeepLoad method calls DataRepository.OrdersProivider.GetByEmployeeID, DataRepository.EmployeeTerritoriesProvider.GetByEmployeeID, and DataRepository.TerritoriesProvider.GetByEmployeeIDFromEmployeeTerritories methods to populate the collection classes found in an Employees object.

There are 3 overloads to DeepLoad

  • DeepLoad(Employees entity)
  • DeepLoad(Employees entity, bool deep)
  • DeepLoad(Employees entity, bool deep Type, DeepLoadType deepLoad,Type [] childTypes)

DeepLoad(entity) and DeepLoad(entity, false) have the same behavior. These methods will load all of the collections for the entity object one level deep.   DeepLoad(employee) will populate OrdersCollection, EmployeeTerritories, and TerritoriesCollection_From_EmployeeTerritories  will be populated. However, EmployeesCollection_From_EmployeeTerritories property of EmployeeTerritories will not be populated.

Calling DeepLoad(entity, true) will recursively call deep load for all of the collection properties in the object. This means that the entire object graph will be loaded. If you’re object model has a lot of relationships, you will be loading a lot of objects into memory. Use this overload with caution.

DeepLoad(Employees entity, bool deep, DeepLoadType deepLoadtype, Type[] childTypes) overload allows you to specifiy which collections you want to load.  The DeepLoadType enumeration has three values

  • Ignore
  • IncludeChildren
  • ExcludeChildren

Choosing Ignore will cause the method to exit without doing anything. IncludeChildren and ExcludeChildren change the childTypes array to either an inclusionary list or exclusionary list. When you use DeepLoadType.IncludeChildren, the types in the the childTypes array will be loaded. With DeepLoadType.ExcludeChildren, the types in the childTypes array will not be loaded.

Let’s look at an example. This is an example console application that is attached to this post. (The deep flag for Many-Many relations is commented out when the code is generated, you need to un-comment them on to follow this example). Let’s load an employee object and Run Deep Load.

Employees emp = DataRepository.EmployeesProvider.GetByEmployeeID(9);

//this loads all child collections one level deep

//it is the same call (litrally) as DeepLoad(emp,false);

DataRepository.EmployeesProvider.DeepLoad(emp);

Console.WriteLine("Employee Orders = " + emp.OrdersCollection.Count.ToString());

Console.WriteLine("Employee Territories = " + emp.TerritoriesCollection_From_EmployeeTerritories.Count.ToString());

The Results from this call is that the OrdersCollection, TerritoriesCollection_From_EmployeeTerritories, EmployeeTerritoriesCollection are populated. The EmployeeTerritoriesCollection contains only the elements from the many-many table, EmployeeId and TerritoryId. While the TerritoriesCollection_From_EmployeeTerritories collection has the entire Territory object fore each of Territory assocatiated.

The output of this is

Employee Orders = 43

Employee Territories Collection = 7

Territories = 7

Let’s Look at the first Order in the OrdersCollection:

Orders order = emp.OrdersCollection[0];

Console.WriteLine("Order Details Count = " + order.OrderDetailsCollection.Count.ToString());

Since we didn’t set the deep flag to true, the OrdersDetailCollection count will be 0.

If we change the DeepLoad call to: DataRepository.EmployeesProvider.DeepLoad(emp, true);

every collection property for every object associated with Employee will be populated. Now,  the order.OrderDetailsCollection.Count will equal 4.

If you have a highly connected object structure, you can see how you can get into trouble quickly with the deep flag turned on. By loading all of those child collections in memory, your going to run into problems quickly.   That is why there is a third overload that allows you to specify which child types you want to load. Suppose you do need the OrdersCollection, but no other collections. You can use this call:

DataRepository.EmployeesProvider.DeepLoad(emp,true,DeepLoadType.IncludeChildren, new Type[]{typeof(OrdersCollection)});

It is important to note only OrdersCollection will be loaded, none of the child types within OrdersCollection will be loaded even though you set deep to true. You can continue along the object graph if you want by adding them to the childType array. If you want to load Orders and OrderDetails:

DataRepository.EmployeesProvider.DeepLoad(emp,true,DeepLoadType.IncludeChildren, new Type[] {typeof(OrdersCollection),typeof(OrderDetailsCollection)});

This call will load all of the OrdersCollection and all of the OrderDetails for every Order in the collection.

The opposite effect will occur if you use DeepLoadType.ExcludeChildren

DataRepository.EmployeesProvider.DeepLoad(emp,true,

DeepLoadType.ExcludeChildren, new Type[]{typeof(OrdersCollection)});

Will load the TerritoriesCollection_From_EmployeeTerritories, EmployeeTerritoriesCollection, but not the OrdersCollection.

I have not yet experimented with DeepSave, however I expect it to have the same behavior. If I find any differences, I will write up another article detailing any difference between DeepLoad and DeepSave

Thanks,
John Teague
------------------------------
Member of the .NetTiers team
http://www.nettiers.com
------------------------------