Sql To Linq(100分). select*from aTab where id in (select pid from aTab whre Cstr='冲突') or pid in (select pid from aTab whre Cstr='冲突')
------解决方案-------------------- static void Main(string[] args) { List<Person> list = new List<Person>(); Person person = null; for (int i = 0; i < 5; i++) { person = new Person(); person.Id = Guid.NewGuid(); person.Name = i.ToString(); person.Age = i + 20; person.Total = 7; list.Add(person); } for (int i = 0; i < 5; i++) { person = new Person(); person.Id = Guid.NewGuid(); person.Name = i.ToString(); person.Age = i + 20; person.Total = i; list.Add(person); }
int[] values = (from c in list where c.Name == "2" select c.Total).ToArray<int>(); var q = from c in list where values.Contains(c.Total) select c; foreach (Person p in q) { Console.WriteLine(p.Name+" "+p.Id+" "+p.Total); } }
你看看吧,看是不是你想要的东西,我想应该差不多了
------解决方案-------------------- var pids = from p in db.aTabs where p.Cstr == "冲突" select p.pid; var qq = from q in db.aTabs where pids.Contains(q.id) || pids.Contains(q.pid) select q;
------解决方案--------------------
var query= (from o in db.aTabs where o.Cstr =="冲突" select o).First(); var q = db.aTabs.Where(p => p.aTabs.Contains(query)).ToList(); 参考