[Quote=引用 1 楼 yezie 的回复:]
设aa表的a1主键,tt表t2外键,还有t3等字段
from m in aa
where id = 123
select new
{
id = m.a1,
t3 = m.tt.t3 //设置外键了就能这样取值,自动join
}
[/Quote]
能用了,还是得把所有的表放在一个设计器里,自己折磨自己,
[Quote=引用 1 楼 yezie 的回复:]
设aa表的a1主键,tt表t2外键,还有t3等字段
from m in aa
where id = 123
select new
{
id = m.a1,
t3 = m.tt.t3 //设置外键了就能这样取值,自动join
}
[/Quote]
这个方法不能用
LINQ使用JOIN
var joinquery = from o in OrderTable.Select()
join c in CustomerTable.Select() on o.CustomerID equals c.CustomerID into x
from xx in x.DefaultIfEmpty(
new Customer() { CustomerID = "UnKnown", CompanyName = "UnKnown Company" })
join e in EmployeeTable.Select() on o.EmployeeID equals e.EmployeeID into y
from yy in y.DefaultIfEmpty(
new Employee() { EmployeeID = -1, Name = "UnKnown", City = City.北京 })
select new
{
OrderInfo = o,
CustomerInfo = xx,
EmployeeInfo = yy
};