Linq To Entity 多表联合查询

时间:2022-10-06 13:02:11
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqToEntity
{
class Program
{
static void Main(string[] args)
{
//点击项目右键-添加->新建项->ADO.NET实体数据模型,然后..选择你需要的表,点击完成。这里我选择是数据库是sales表的名字是xs,xs_kc默认生成了一个实体容器名称 salesEntities

salesEntities salesEn = new salesEntities();

var result = from xs in salesEn.xs
from xs_kc in salesEn.xs_kc

where string.Equals(xs_kc.课程号, "206")
&& xs_kc.成绩 > 80
&& xs.学号 == xs_kc.学号

select new
{
xs.姓名,
xs_kc.成绩
};

foreach (var item in result)
{
Console.WriteLine(item.姓名 + ":" + item.成绩);
}


Console.ReadLine();


}
}
}