本文介绍了实体框架中的返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用下拉值在高级图表中显示数据代码 我尝试过:
i try this code for display data in high charts using dropdown value What I have tried:
[WebMethod] public static string jqufunc(int year) { string res = "["; ProjectdbEntities a = new ProjectdbEntities(); var b = a.Catg_type; foreach (var c in b) { res += "'" + c.Catg_type1 + "',"; } res = res.Substring(0, res.Length - 1); res += "]"; //for program type var allprogs = a.Program_type; string res2 = "["; foreach (var pr in allprogs) { res2 += "{name: '" + pr.Prog_name + "',"; string res3 = "["; var y = a.Year_info; foreach (var g in y) { res3 += "'" + g.year + "',"; //for category type var allcats = a.Catg_type; res2 += "data:["; foreach (var ct in allcats) { res2 += a.Std_info.Where(t => t.Catg_id == ct.Catg_id && t.Prog_id == pr.Prog_id && t.year_id==g.year_id).Count().ToString().ToList() + ","; } res2 = res2.Substring(0, res2.Length - 1); res2 += "]"; res2 += "},"; } res2 = res2.Substring(0, res2.Length - 1); res2 += "]"; //return (from c in a.Year_info where c.year_id == year select c).ToList(); return res + "*" + res2; } }但显示错误 'WebApplication1.WebForm1.jqufunc(int)':并非所有代码路径都返回一个值 i已经返回一个值 任何解决方案
but this shows error 'WebApplication1.WebForm1.jqufunc(int)': not all code paths return a value i already return a value any solution
推荐答案您的代码 - 过度简化: Your code - over-simplified: [WebMethod] public static string jqufunc(int year) { foreach (var pr in allprogs) { return res + "*" + res2; } }
您可以看到此代码仅在时返回任何内容allprogs 至少有一个成员 - 而且不会承诺... 如果没有成员,代码将永远不会进入 foreach 并且不会点击返回 ...
You can see that this code will return anything only if allprogs has at least one member - and that's not promised nowhere... If there are no members the code will never enter the foreach and will not hit the return...
我们不知道你的代码背后的逻辑,似乎很多循环是否有 return 关键字应该放在循环之外,因为你要返回一些值。 在函数的最后一行返回变量(res)。 始终遵循此模式 We dont know about the logic behind your code, seems lot of looping are there the return keyword should be placed outside the loop since you are returning some value. return the variable (res) at the last line of the function. always follow this pattern public ReturnType MyMethod() { ReturnType returnValue = default(ReturnType); // // Your Code (for loop or any ) // return returnValue; }
更多推荐
实体框架中的返回值
发布评论