[c#]How can I use CompiledQuery in Entity(object context)?

lisah

New Member
I used the linq to fetch the data from database before, but it looks like using CompiledQuery with Linq should be than using Linq by itself.I've try to use CompiledQuery, but it's throwing an exception.Following is my code:\[code\]static readonly Func<myEntity, int?, List<myDataModel>> s_compiledQuery2 =CompiledQuery.Compile<myEntity, int?, List<myDataModel>>( (ctx, NULLUserId) => ( from jlr in ctx.C_InternetCafe where jlr.USER_ID != NULLUserId select new myDataModel { pid = jlr.PC_ID ?? 0, uid= jlr.USER_ID ?? 0 } ).ToList());static List<myDataModel> CompiledQuery2(){ using (myEntity context = new myEntity()) { int? UserId = null; List<myDataModel> orders = s_compiledQuery2.Invoke(context, UserId); return orders; }}public List<myDataModel> getCustomerInf(){ return CompiledQuery2();}\[/code\]I just want to fetch the values "PC_ID" and "USER_ID" from table \[code\]C_InternetCafe\[/code\], and add them to myDataModel whose datamember has \[code\]pid\[/code\] and \[code\]uid\[/code\].
 
Top