且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

实体框架4.1代码第一 - 如果一对多的关系ICollections被初始化

更新时间:2022-11-04 22:55:03

第一个版本是正确的。它可以让你来初始化集合,当你创建一个新的实体,而是在同一时间,它可以让EF来时,它物化从数据库加载实体,由懒加载动态代理wrapps它初始化集合。

The first version is correct. It will allow you to initialize collection when you are creating a new entity but in the same time it will allow EF to initialize the collection when it materializes the entity loaded from DB and wrapps it by dynamic proxy for lazy loading.