我在Sql数据库中有两个表,分别是Users和UserEducation表。用户表中有多条记录,对于每个用户,用户教育表中有一条记录。我想通过加入这两个表在网格视图中显示所有记录?如何使用实体框架执行此操作?
或使用Linq来实体和联接表。
using ( var context = new YourContext)
{
var users = context.UserDbSet;
var userEdications = context.UserEdication.DbSet ;
var joinedTables = from user in users
join userEdication in userEdications on user.userId = userEdication.userId
select new OutPutEntity
{
Name = user.Name,
Edication = userEdication.Edication
}
gridView.DataSource = joinedTables.toList(); // should be placed outside the using. (here just as a sample)
}
优势-您可以在IQurable级别上指定输出格式。缺点-它看起来很复杂。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句