日期:2014-05-20  浏览次数:20824 次

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();
参考

------解决方案--------------------
首先,你的SQL很差啊。要知道,你的写法将对SQL查询效率是一个很大的打击。你首先应该把它写为Inner Join查询,然后就知道平时怎么写SQL了。

同时也就知道如何写Linq了。
------解决方案--------------------
探讨
var query= (from o in db.aTabs
            where o.Cstr =="冲突"
            select o).First();
var q = db.aTabs.Where(p => p.aTabs.Contains(query)).ToList();
参考


------解决方案--------------------
探讨
var query= (from o in db.aTabs
            where o.Cstr =="冲突"
            select o).First();
var q = db.aTabs.Where(p => p.aTabs.Contains(query)).ToList();
参考


------解决方案--------------------
帮 顶
------解决方案--------------------
帮顶
------解决方案--------------------
探讨
var query= (from o in db.aTabs
            where o.Cstr =="冲突"
            select o).First();
var q = db.aTabs.Where(p => p.aTabs.Contains(query)).ToList();
参考


------解决方案--------------------
探讨
var query= (from o in db.aTabs
            where o.Cstr =="冲突"
            select o).First();