在Linq to Sql中查询多个表 [英] Querying multiple tables in Linq to Sql

查看:75
本文介绍了在Linq to Sql中查询多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们,我有3个表,我需要从这些表中返回一组结果.该应用程序是用C#编写的,并且所有数据都是使用linq to sql获取的.这些表是User,PermissionGroup和Subscription,user和Permission表都可以在Subscription表中都有一个条目,因此我想返回每个User或Permission Group拥有的所有Subscription.在sql中做起来很容易,但这不是我在这里需要的.非常感谢您的帮助.谢谢大家

Hey guys, I have 3 tables which I need to return a set of results from. The application is written in c# and all the data is got using linq to sql. the tables are User, PermissionGroup and Subscription, The user and Permission table can both have an entry in the Subscription table, so I wanna return all the Subscriptions that each User or Permission Group have. It is pretty easy to do in sql but it''s not whay I need here. Any help is very much apreciated. Thanks guys

推荐答案

我有一个例子..也许对您有帮助



i have an example ..may it will help you



var albums = (from a in db.artists
                          where a.artistId == 1
                          join sb in db.singbies on a equals sb.artist
                          join t in db.tracks on sb.track equals t
                          join al in db.albums on t.album equals al
                          select al).Distinct();

return albums.ToList() as List<album>;




或者您可以通过您的简单sql查询,然后将其转换为linq到sql




or you can past ur simple sql query then i will convert it to linq to sql


这篇关于在Linq to Sql中查询多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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