【发布时间】:2018-02-19 15:04:14
【问题描述】:
我需要在 c# 中为以下 sql 查询编写一个 linq 查询。 我在实现 where,not in,orderby 和 descending 方面没有问题,但问题是查询 sql xml 列
SELECT [ID]
,[QueuedTime]
,Parameters.query('data(Root/Root/@type)').value('.', 'varchar(500)') as CommandName //how to implement this line in linq
,[Status]
,[CurrentRetryCount]
,[MaxRetryCount]
,[RetryDelaySeconds]
,[CompletedTime]
,[LastTriedTime]
,[LastError]
,Parameters
,[PrincipalString]
FROM [AppServer].[dbo].[RequestQueue]
where interfacename = 'ICommunicationsService'
and MethodName = 'ProcessCommand'
and status not in (1,2)
order by id desc
下面的查询将满足 where,not in 和降序条件。我担心如何实施 'Parameters.query('data(Root/Root/@type)').value('.', 'varchar(500)') as CommandName' in linq
var unwantedStatus = new[] { 1, 2 };
var operationTimedOutTasks = context.TblRequestQueues
.Where(t => t.MethodName == "ProcessCommand" && !unwantedStatus.Contains(t.Status))
.OrderByDescending(t => t.ID)
.ToList();
【问题讨论】:
-
this 之类的东西可能会起作用,尽管我不确定它的性能如何