c# - Implicitly typed local variables must be initialized -


here code :- how initialize data?

var data;  if (mode == "view")                 {                     data = (from in ctx.tblemployee                             a.companyid == companyid                             join b in ctx.tblto_shiftschedule on a.id equals b.employeeid                             b.companyid == companyid                                                         select new { a, b, c, d }).tolist();                 }                 else                 {                     data = (from in ctx.tblemployee                             a.companyid == companyid                                                         select new { a, b, c, d }).tolist();                 } 

you can't initialize anonymous type, so:

var data = mode == "view"  ? (from in ctx.tblemployee                         a.companyid == companyid                         join b in ctx.tblto_shiftschedule on a.id equals b.employeeid                         b.companyid == companyid                                                     select new { a, b, c, d }).tolist() : (from in ctx.tblemployee                         a.companyid == companyid                                                     select new { a, b, c, d }).tolist(); 

Comments

Popular posts from this blog

mysql - FireDac error 314 - but DLLs are in program directory -

git - How to list all releases of public repository with GitHub API V3 -

c++ - Getting C2512 "no default constructor" for `ClassA` error on the first parentheses of constructor for `ClassB`? -