将sql server中的查询转换为LINQ [英] convert query in sql server to LINQ

查看:80
本文介绍了将sql server中的查询转换为LINQ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

我无法将SQL Server中的此查询转换为LINQ



  SELECT  dbo.ReportType.Name 
FROM dbo.Center INNER JOIN
dbo.SwitchType ON dbo.Center.ID = dbo.SwitchType。 ID FULL JOIN
dbo.ReportType ON dbo.Center.ID = dbo.ReportType.ID





请帮助我。

解决方案

1.转到sql server并创建一个[VIEW]并将表连接在一起。

2.添加查看到LINQ to SQL

3 。

 DataClasses1DataContext db =  new  DataClasses1DataContext(); 
ViewNameBindingSource.DataSource = db.ViewName.Where(c = > c.Name == KeySearch)。选择(c => c);
// ViewViewBindingSource用于ReportView的BindingSource







2)示例来自linq

  //   linq to entities三表连接查询 
var query = 来自 p db.QuizParticipants
join db.ParticipantPoints on p.id
等于points.participantId into participantGroup
来自 po participantGroup
join winners in db.Winners on p.id
equals winners.participantId into winnersGroup
from w in winnersGroup
其中 p.hasAttended == 1 && p.weeknumber == weeknumber
选择 new
{
ParticipantId = p.id,
HasAttended = p.hasAttended,
Weeknumber = p.weeknumber,
UmbracoMemberId = p.umbMemberId,
Points = po.points,
HasWonFirstPrize = w.hasWonFirstPrize,
HasWonVoucher = w.hasWonVoucher
};


 选择 * 来自 PersonInfo 
其中代码

选择 a.Code 来自 PersonInfo as a,TradeElamieh as b
其中 a.Code = b.person1 b.Actual = 1 (a.Investor_ID 喜欢 ' 1338% ' a.Investor_ID 喜欢 ' 1339%'
b.date> ' 2012-01-01' a.Investor_ID IS NOT NULL


Hello
I cant convert this Query in SQL Server to LINQ

SELECT dbo.ReportType.Name
FROM   dbo.Center INNER JOIN
       dbo.SwitchType ON dbo.Center.ID = dbo.SwitchType.ID FULL JOIN
       dbo.ReportType ON dbo.Center.ID = dbo.ReportType.ID



Pleas help me .

解决方案

1.Go to sql server and create a [VIEW] and join table's together.
2.Add View to LINQ to SQL
3.

DataClasses1DataContext db = new DataClasses1DataContext();
ViewNameBindingSource.DataSource = db.ViewName.Where(c => c.Name=="KeySearch").Select(c=>c);
//ViewNameBindingSource BindingSource For ReportView 




2)Example By linq

//linq to entities three table join query
var query = from p in db.QuizParticipants
            join points in db.ParticipantPoints on p.id 
            equals points.participantId into participantsGroup
            from po in participantsGroup
            join winners in db.Winners on p.id 
            equals winners.participantId into winnersGroup
            from w in winnersGroup
            where p.hasAttended == 1 && p.weeknumber == weeknumber
            select new
            {
                ParticipantId = p.id,
                HasAttended = p.hasAttended,
                Weeknumber = p.weeknumber, 
                UmbracoMemberId = p.umbMemberId,
                Points = po.points,
                HasWonFirstPrize = w.hasWonFirstPrize,
                HasWonVoucher = w.hasWonVoucher                                    
            };


select * from PersonInfo
where code
in
(select a.Code from PersonInfo as a ,TradeElamieh as b
where a.Code=b.person1 and b.Actual=1 and (a.Investor_ID like'1338%' or a.Investor_ID like'1339%')
 and b.date>'2012-01-01' and a.Investor_ID IS NOT NULL)


这篇关于将sql server中的查询转换为LINQ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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