开发者

linq compiled query, class field

开发者 https://www.devze.com 2023-03-06 14:02 出处:网络
How can I insted ofpublic var compiledQuery write Func < MYEntities,string, ???> public var compiledQuery = CompiledQuery.Compile((AddresEntities ctx, string name) =>

How can I insted of public var compiledQuery write Func < MYEntities,string, ???>

    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});

When I try it like this i get error: Only parametar less constructor are suported

 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)));


you can try. Hope this will work

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

精彩评论

暂无评论...
验证码 换一张
取 消