in

@Prog! - ASP.NET(C#) AJAX -

ASP.NET(C#) 2.0 & ASP.NET Ajax (ATLAS) のメモ書き

LINQ 指定したレコード数を収得する(Take)

最新の投稿は、投稿日時: 2008/01/02 9:57 投稿者: ASANO です。スレッドには 1 件の返答があります。
ページ 1 / 1 (2 アイテム)
投稿の並べ替え: 前へ 次へ
  • 2008/01/02 9:57

    LINQ 指定したレコード数を収得する(Take)

    using System;
    using System.Linq;
    using System.IO;
    using System.Collections.Generic;

    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[ args)
            {
                using (DataClasses1DataContext dataContext = new DataClasses1DataContext())
                {
                    StreamWriter sw = new StreamWriter(@"d:\log.txt");
                    sw.AutoFlush = true;
                    TextWriter tw = TextWriter.Synchronized(sw);

                    dataContext.Log = tw;

                    var r = dataContext.Table_1.Where(t => t.ID > 3).OrderByDescending(t => t.ID).Take(5);

                    r.ToList().ForEach(delegate(Table_1 t) {
                        Console.WriteLine("{0}:{1}", t.ID, t.Number);
                    });
                }

                Console.ReadLine();
            }
        }
    }

  • 2008/01/02 9:57 回答元:

    Re: LINQ 指定したレコード数を収得する(Take)

    SELECT TOP (5) [t0].[ID], [t0].[Number]
    FROM [dbo].[Table_1] AS [t0]
    WHERE [t0].[ID] > @p0
    ORDER BY [t0].[ID] DESC
    -- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [3]
    -- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.21022.8

ページ 1 / 1 (2 アイテム)