2011-04-29 41 views
0

是否有可能將此映射到一個實體?EntityFramework Code首先,是否可以映射此

select x,y,z, (select count(*) from othertable where tableid=table.id) as othertablecount 
from table t 

我想這映射到一個類,它看起來像這樣:

public class Stuff 
{ 
    public string x { get; set; } 
    public string y { get; set; } 
    public string z { get; set; } 
    public int count { get; set; } 
} 

回答

0

號你應該把它映射正確的收集和使用的投影查詢:

class Stuff 
{ 
    ... 
    public virtual ICollection<OtherStuff> { get; set; } 
} 

var stuffWithCount = from stuff in myContext.Stuff 
        select new 
          { 
           stuff.x, ... 
           count = stuff.OtherStuff.Count() 
          }; 
+0

啊哈,當然這就是解決方案。謝謝! – 2011-05-01 05:28:52

相關問題