2011-05-15 73 views
1

我怎樣才能insted的公共變種compiledQueryFunc鍵< MYEntities,串,???>LINQ編譯的查詢,類別字段

public var compiledQuery = CompiledQuery.Compile((AddresEntities ctx, string name) => 
    from x in ctx.User 
    where x.Name.Contains(name) 
    select new { x.Name, x.Phone}); 

當我嘗試像這樣我得到錯誤:僅參數表較少構造函數被支持

public static Func<AddresEntities, string, IQueryable<MYClass>> compiledQuery = 
      CompiledQuery.Compile((AddresEntities ctx, string name) => 
           (from x in ctx.Users 
            where x.Name.Contains(name) 
            select new MYkontakt(x.Name, x.Phone))); 

回答

1

你可以試試。希望這將工作

IEnumerable<yourType> compiledQuery = CompiledQuery.Compile((AddresEntities ctx, string name) => 
from x in ctx.User 
where x.Name.Contains(name) 
select new yourType { x.Name, x.Phone}); 
+0

它不起作用。 – 2011-05-16 07:07:50

+0

請給出您的錯誤 – anishMarokey 2011-05-16 07:09:01

+0

無法初始化類型'Database.User_Services.MyUser'集合初始化程序 ,因爲如果它不是IEnumerable類型,它不會實現'System.Collections.IEnumerable' – 2011-05-16 07:46:27