EF2:有没有办法在不加载相关实体的情况下向EntityCollection添加实体?

时间:2010-05-25 02:24:58

标签: c# entity-framework

我可以在实体上设置EntityReference,而不必按如下方式加载相关实体:

this.CategoryReference.EntityKey = new EntityKey("MyEntities.CategorySet", "Id", 12);

因此,我可以将我正在处理的实体的类别设置为任何具有id 12的类别,而无需访问数据库。

但是有没有办法在EntityCollection上做这个或类似的东西?因此,如果我现在有多个类别而不是一个类别,我现在想做类似下面的事情,尽管它不起作用:

// stand-in category
var categoryStandIn = new Category { EntityKey = new EntityKey("MyEntities.CategorySet", "Id", 12) }
this.Categories.Add(categoryStandIn);

1 个答案:

答案 0 :(得分:1)