0

次の質問で私の語彙がずれていたら申し訳ありません。

そのデータベース内のテーブルに対して複数のリレーションシップを持つ SQL データベースがあります。このデータベースの DataContext を作成し、そのデータを呼び出すために使用される関数のリポジトリを作成しました。

私の質問は、関係(複数のリンクされたテーブル)のためです。

次のように、結果を保持し、必要なテーブルの列データのみを取得する独自のクラス オブジェクトを作成する必要があります。

   public IQueryable<VM_userLogs> getUserLogsVM(Nullable<DateTime> startDate, Nullable<DateTime> endDate)
{
    if (startDate == null) {
        startDate = Convert.ToDateTime("01-01-1900");
    }

    if (endDate == null) {
        endDate = Convert.ToDateTime("01-01-2900");
    }

    IQueryable<VM_userLogs> logs = from l in ctx.tools_trt_userLogs 
                   where l.timeStamp >= startDate & l.timeStamp <= endDate 
                   select new VM_userLogs {
                            LOG_ID = l.logId,
                            NTLOGIN = l.ntLogin,
                            PRODUCT = l.productName,
                            SEGMENT = l.segmentName,
                            PRIORITY = l.priority,
                            GROUP = l.groupName,
                            ANSWER = l.answerText,
                            TIMESTAMP = l.timeStamp,
                            URL = l.url
                        };
    return logs;
}

または、データコンテキストから基になるオブジェクトを呼び出すだけで、パフォーマンスに大きな影響を与えることはできません...次のように:

    public IQueryable<tools_trt_userLogs> getUserLogs(Nullable<DateTime> startDate, Nullable<DateTime> endDate)
{
    if (startDate == null)
    {
        startDate = Convert.ToDateTime("01-01-1900");
    }

    if (endDate == null)
    {
        endDate = Convert.ToDateTime("01-01-2900");
    }

    IQueryable<tools_trt_userLogs> logs = from l in ctx.tools_trt_userLogs
                                   where l.timeStamp >= startDate & l.timeStamp <= endDate
                                   select l;
    return logs;
}
4

0 に答える 0