1

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)));
jasin_89
  • 1,993
  • 7
  • 30
  • 41

1 Answers1

1

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});
anishMarokey
  • 11,279
  • 2
  • 34
  • 47
  • Cannot initialize type 'Database.User_Services.MyUser' with a collection initializer because it does not implement 'System.Collections.IEnumerable' – jasin_89 May 16 '11 at 07:46
  • if it is not an IEnumerable type. it think you can return only anonymous type :( – anishMarokey May 16 '11 at 08:25
  • So if I implement IEnumerable in my class MyUser this will be slowed. – jasin_89 May 16 '11 at 16:20
  • So it is impossibile to have compiledQuery as a Class field which have ***select new** statement, if there is some workaround this if someone knows please write it here. – jasin_89 May 17 '11 at 08:06