English 中文(简体)
林克按可取消的日期分组,并将之作为标准
原标题:Linq grouping by nullable datetime and using this as criteria

我正在争取在伙伴关系中设置一个可取消的日期栏[DateInsp]。 NET 使用了SubSonic3、Linq、MSQ服务器,2005年。

当日一栏[DateInsp]不允许无效时,我就这样做了。 一项新要求迫使我设置了[DateInsp]栏,使“DateInsp”一栏落空,现在我正在努力使这一功能再次正常运转。

Problem 1: I need to first render a dropdown list of the 7 most recent inspection dates for a given inspector (this is a grouped list of the 7 most recent dates for the inspector). Here is the TSQL that I need to convert to Linq syntax:

declare @InspectorID varchar(5)
set @InspectorID =  GPA 

select top 7 convert(nvarchar(30), [DateInsp], 101) InspectedDate
from [dbo].[IncomingInspection]
group by [InspectorID], convert(nvarchar(30), [DateInsp], 101)
having [InspectorID] = @InspectorID
order by convert(nvarchar(30), [DateInsp], 101) desc

如果我能够适当利用Linq进行这项工作,BUTI能够/可以建造一个储存的假体,将日期清单退回,并将日期降为。 公平够了。 我与林克辛塔克斯交战,因此,我们非常赞赏在这方面的任何帮助。

<><><><>>> 我需要利用上文提到的减员中选定的日期,为这一检查员记录正确无误和准确的日期。 同样,这是一个不可否认的时代领域,对我来说,这是真正的 stick点。

这里是最初的Linq syntax,满足了在我不得不改变时间范围以允许新生活之前的要求:

    Dim query = (From i In db.IncomingInspections _
        Where i.InspectorID = User.Identity.Name _
        Group By Key = New With {i.DateInsp} Into Group _
        Order By Key.DateInsp Descending _
        Select Key = New With {.DateInsp = Key.DateInsp.ToShortDateString}).Take(7)

这份资料载于VB。 NET并使用一些使我头部受伤的Linq syntax。 如果你能够提供C# syntax来完成这项工作,我可以将其翻译到VB。 NET本人。

http://www.un.org。

出于某种原因,我只能使用。 价值财产;我获得: 成员价值不支持

如果我试图将日期与条款的比较相加的话,我会得到:“Incorrect syntax near <

<>ENDIT

感谢很多,

方 法

最佳回答

我接着利用了2个储存的程序来解决这一问题,从而消除了林克辛塔克斯在此的必要性:

这里是我用来获得最后7个检查日期清单的TSQL(仅按日期划分):

select top 7 convert(nvarchar(30), [DateInsp], 101) InspectedDate
from [dbo].[IncomingInspection]
group by [InspectorID], convert(nvarchar(30), [DateInsp], 101)
having [InspectorID] = @InspectorID
order by convert(nvarchar(30), [DateInsp], 101) desc

这里是我用来 gr弄检查员检查记录的过滤清单和在下降时选定的检查日期(仅使用标准说明中的日期部分):

select [ID]
,[InspectorID]
,[DateInsp]
-- (more fields here)
from [dbo].[IncomingInspection]
where [InspectorID] = @InspectorID and DATEADD(dd, 0, DATEDIFF(dd, 0, [DateInsp])) = DATEADD(dd, 0, DATEDIFF(dd, 0, @DateFilter))

有时 我只得去工作,而不是新的和光辉。 有时,我与林克最简单的东西进行了斗争,我认为这既是因为林克是我的新鲜事,我是在博爱的头上。 NET syntax,特别是在与Linq合并时。

问题回答

在C#中回答问题,但我在此对你的询问作了解释:

问题1。

您在问题中使用having,并将日期改为指示。 我看不出这两种行动都需要。

string inspectorId = "GPA";

List<DateTime?> someDates = db.IncomingInspection
  .Where(insp => insp.InspectorId == inspectorId)
  .Select(insp => insp.InspectedDate)
  .Distinct()
  .OrderByDescending(d => d)
  .Take(7)
  .ToList();

问题2。

有两种情况:要么是用户的,要么是用户的。 简言之,要针对每个案件发出询问。 简言之,我感到,我在这里怀念这一意图。

DateTime? selectedDate = control.SelectedValue;

List<IncomingInspection> someRecords = null;

if (selectedDate.HasValue())
{
  DateTime selectedDateValue = selectedDate.Value;
  someRecords = db.IncomingInspection
    .Where(insp => insp.InspectorId == inspectorId)
    .Where(insp => insp.InspectedDate == selectedDateValue)
    .ToList();
}
else
{
  someRecords = db.IncomingInspection
    .Where(insp => insp.InspectorId == inspectorId)
    .Where(insp => insp.InspectedDate == null)
    .ToList();
}




相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签