Write this SQL query in LINQ to Entity format -


i have sql query need convert linq entity

select kv.keyid, kv.keyvotid, v.votid, v.fullname e_keyvot kv join e_vot v on kv.votid = v.votid kv.keyid=2 order v.fullname 

this have tried i'm sure not correct:

public function getkeyvot() iqueryable(of ems_keyvot)   try      dim _objquery iqueryable(of ems_keyvot, ems_vot) = _          in context.ems_keyvot           join b in context.ems_vot on a.votid equals b.votid          a.keyid = pub_keyid          order b.fullname      return _objquery    catch ex exception    end try  end function  

based on query, issue have return types don't agree query. query returns iqueryable(of ems_keyvot, ems_vot), function expecting iqueryable(of ems_keyvot).

in query, projecting values both tables. since can't return anonymous type function, need create class return results:

public class votes   public property keyid integer   public property keyvotid integer   public property votid integer   public property fullname string end class 

with that, can modify query follows:

 dim _objquery iqueryable(of ems_keyvot, ems_vot) = _      in context.ems_keyvot       join b in context.ems_vot on a.votid equals b.votid      a.keyid = pub_keyid      order b.fullname      select new votes { .keyid = a.keyid, .keyvotid = a.keyvotid, .votid = b.votid, .fullname = b.fullname } 

also change function definition

public function getkeyvot() iqueryable(of votes) 

one other note, see have try catch block, aren't doing exception. if can't handle exception, remove block , let bubble can.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -