LINQ的问题(C#) [英] problem with linq (C#)
本文介绍了LINQ的问题(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var pom= from k in dataContext.student_gods
where k.skgod==System.Convert.ToString(2002/03)
select k;
foreach(var i in pom){
var predmeti = from m in dataContext.student1s
where m.id_stud ==System.Convert.ToString(i.id_stud)
select m;
}
return View(predmeti);
这是建议后code。我有一个错误:名称predmeti不会在目前的情况下存在。如果foreach循环我不知道如何初始化之前申报变种predmeti
This is code after suggestions. I have one error: the name predmeti does not exist in current context. If declare var predmeti before foreach loop I dont know how to initialize
推荐答案
我觉得你是过于复杂这一点,并冒着臭名昭著的的foreach
/捕获问题(因为LINQ使用延迟执行)。也许只是:
I think you are over-complicating this, and risking the infamous foreach
/capture issue (since LINQ uses deferred execution). Perhaps just:
var pom= from k in dataContext.student_gods
where k.skgod==System.Convert.ToString(2002/03)
select k.id_stud;
var list = pom.ToList();
var predmeti = from m in dataContext.student1s
where list.Contains(m.id_stud)
select m;
return View(predmeti);
这篇关于LINQ的问题(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文