Linq从不同的表中提取数据 [英] Linq to extract a data from different tables

查看:103
本文介绍了Linq从不同的表中提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Table1
 
ID   Legal Name   TypeFK.
1     S1            2
2     S2            1

Table2

ID   Type Name   
1     type1      
2     type2    

Required Result
ID     Legal Name   Type Name
1          S1        type2
2          S2        type1

how to use linq to get this ans...

推荐答案

尝试以下方法:
Try this:
var query  = from t1 in db.Table1
join t2 in db.Table2 on t1.ID equals t2.ID select new { t1.ID, t1.LegalName, t2.TypeName}


请参考 [


Refer this[^] for more information.


--Amit.




检查这些链接.

http://stackoverflow.com/questions/2379747/create-combined-datatable-from-two-datatables-joined-with-linq-c-sharp [ LINQ-加入2个数据表 [如何使用LINQ联接多个数据表 [ ^ ]

希望对您有所帮助.
Hi,

check these links.

http://stackoverflow.com/questions/2379747/create-combined-datatable-from-two-datatables-joined-with-linq-c-sharp[^]
LINQ - join 2 datatables [^]
How to use LINQ to join multiple DataTables[^]

hope it helps.


这篇关于Linq从不同的表中提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆