【发布时间】:2012-09-13 15:32:31
【问题描述】:
我有这样的事情:
var model = forumsDb.Categories
.Select(c => new {c, c.Threads.Count})
.ToList()
我的 Category 对象如下所示(伪代码):
public class Category
{
public int id {get;set;}
public ICollection<Thread> Threads { get; set; }
/***some properties***/
[NotMapped]
public int ThreadCount {get;set;}
}
现在,在我的模型对象中,我有两个项目:model.c 和 model.Count。如何将model.Count 映射到model.c.ThreadCount?
【问题讨论】:
-
你在这里提到了什么模型对象?
-
?我不明白,我在帖子顶部发布的查询给出的那个?它实际上映射到 {Category, int} 对象的匿名类型。
-
我没有看到你的模型有属性 Count
-
是的,它会在我执行查询后自动将 c.Threads.Count 映射到 model.Count,正如我之前所说,我现在想将此 model.Count 映射到 model.c.ThreadCount
标签: c# entity-framework ef-code-first projection