首页 新闻 会员 周边

Entity FrameWork中ObjectSet和ObjectQuery有什么区别

0
悬赏园豆:50 [已解决问题] 解决于 2012-04-24 23:07

根据msdn文档的解释:

ObjectSet表示用于执行创建、读取、更新和删除操作的类型化实体集。

ObjectQuery表示在给定的对象上下文中针对概念模型的类型化查询。

但是还是不清楚用法上有什么区别,什么情况下该使用什么

何以笙箫的主页 何以笙箫 | 初学一级 | 园豆:41
提问于:2012-03-30 14:25
< >
分享
最佳答案
0
 1 //看看Object的成员吧
2 public class ObjectSet<TEntity> : ObjectQuery<TEntity>, IObjectSet<TEntity>, IQueryable<TEntity>, IEnumerable<TEntity>, IQueryable, IEnumerable where TEntity: class
3 {
4 // Fields
5 private readonly EntitySet _entitySet;
6
7 // Methods
8 internal ObjectSet(EntitySet entitySet, ObjectContext context);
9 public void AddObject(TEntity entity);
10 public TEntity ApplyCurrentValues(TEntity currentEntity);
11 public TEntity ApplyOriginalValues(TEntity originalEntity);
12 public void Attach(TEntity entity);
13 public T CreateObject<T>() where T: class, TEntity;
14 public TEntity CreateObject();
15 public void DeleteObject(TEntity entity);
16 public void Detach(TEntity entity);
17
18 // Properties
19 public EntitySet EntitySet { [TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")] get; }
20 private string FullyQualifiedEntitySetName { get; }
21 }
22
23

ObjectQuery应该只提供查询,ObjectSet提供了全套CRUD, 还有Attach,Detach这些的涉及TEntity的变更跟踪的东西。唉,知道ObjectSet的额外接口成员怎么用就应该知道区别了。如果可以使用EF4.1以上,使用DbContext的接口吧。

收获园豆:40
ChatinCode | 老鸟四级 |园豆:2272 | 2012-04-01 13:26
其他回答(2)
0

ObjectQuery这个是查询用的

artwl | 园豆:16736 (专家六级) | 2012-03-30 20:03

ObjectSet也可以用于查询吧

支持(0) 反对(0) 何以笙箫 | 园豆:41 (初学一级) | 2012-03-30 21:49
0
收获园豆:10
dudu | 园豆:30994 (高人七级) | 2012-03-30 22:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册